我需要從 XML 獲取 xlink:label 值(ASSET_1)。<MESSAGE xmlns:xlink="http://www.w3.org/1999/xlink"><ABOUT_VERSIONS><ABOUT_VERSION SequenceNumber="1" xlink:label="ASSET_1" ><CreatedDatetime>2015-08-24T09:30:47Z</CreatedDatetime><DataVersionName>Purchase Example</DataVersionName></ABOUT_VERSION></ABOUT_VERSIONS></MESSAGE>我正在嘗試的 Java 代碼如下所示XPathFactory xpf = XPathFactory.newInstance(); XPath xPath = xpf.newXPath();XPathExpression pathExpression = xPath.compile("MESSAGE/ABOUT_VERSIONS/ABOUT_VERSION"); InputSource inputSource = new InputSource("C:/Sample.xml"); NodeList Nodes = (NodeList) xPath.evaluate("MESSAGE/ABOUT_VERSIONS/ABOUT_VERSION", inputSource, XPathConstants.NODESET);System.out.println("SequenceNumber:: "+xPath.evaluate("MESSAGE/ABOUT_VERSIONS/ABOUT_VERSION/@SequenceNumber", inputSource, XPathConstants.NODE));System.out.println(" "+xPath.evaluate("MESSAGE/ABOUT_VERSIONS/ABOUT_VERSION/@xlink:label", inputSource, XPathConstants.NODE));OutPutSequenceNumber:: SequenceNumber="1"null我在提取 xlink:label 的值時(shí)犯了什么錯(cuò)誤?請(qǐng)幫忙。
1 回答

HUX布斯
TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超6個(gè)贊
您可以使用@*[name()='xlink:label']
代替@xlink:label
. 也切換到@*[local-name()='label']
應(yīng)該可以解決問題。
添加回答
舉報(bào)
0/150
提交
取消