以下是我的XML文件XPath的結果空字符串
<xyzevent xmlns="http://www.xyz.com/common/xyzevent/v1" xmlns:xsi="http://www.w3.org2001XMLSchema-instance">
<header>
----
</header>
<subscription xmlns="http://www.xyz.com/common/xyzevent/source/v1">
<sender></sender>
<receiver>
<clientsubscription>
<servicemap>nanna</servicemap>
</clientsubscription>
</receiver>
</subscription>
</xyzevent>
當我budila org.w3c.dom.Document中從該XML和應用XPathExperssion與表達
/xyzevent/subscription/receiver/clientsubscription/servicemap/text()
結果空字符串。這個表達式有什麼問題?
謝謝
刪除xmlns = http://.../v1後,我可以從這兩個地方獲得值。但是,你能否向我解釋如何在我們在文檔中同時創建名稱空間值時創建NamespaceContext ... – Pokuri
@Pokuri在'NamespaceContext'中註冊兩個單獨的前綴,例如, 'event'和'source'都有適當的URI。您的XPath表達式將成爲'/ event:xyzevent/source:subscription/source:receiver/...' – Barend
但NamespaceContext需要一個namespaceURI和一個或多個前綴。那麼如何將兩個NamespaceContext傳遞給XPath.setNamespaceContext(namespaceContext);方法 – Pokuri