0
我有一个情况在这里,我需要解析以下XML:解析有两个相同的孩子一个XML节点
<Attributes>
<Map>
<entry key="band" value="25" />
<entry key="triggerSnapshots">
<value>
<Map>
<entry key="AttributeChange">
<value>
<Attributes>
<Map>
<entry key="band" value="45" />
</Map>
</Attributes>
</value>
</entry>
<entry key="ManagerTransfer" value="7262079" />
<entry key="needsCreateProcessing">
<value>
<Boolean>true</Boolean>
</value>
</entry>
</Map>
</value>
</entry>
</Map>
</Attributes>
问题:
在上面的XML我需要皮卡输入密钥的值为
band=25
,而不是band=45
的输入密钥。当我使用解析我的XML:NodeList nodes = doc.getElementsByTagName("entry");
我第一次拿到带价值25
并将其存储在地图中,然后当我带值45
在地图乐队值25
得到由覆盖45
。我只需要解析XML的方式,我得到的带值为25
而不是45
。
如果XML并不大的特定XML节点和值,那么我建议的XPath parser..in你可以把整个路径如 XPath xpath = XPathFactory.newInstance()。newXPath(); map =(String)xpath.evaluate(“/ Attributes/Map/entry/value/Map”,doc,XPathConstants.STRING); –
这个嵌套是否有限制? –