Looking for JDOM2 XPath examples

╄→尐↘猪︶ㄣ 提交于 2019-12-07 11:17:48

问题


I am using JDOM2 for the first time and I am looking for some XPATH based examples.

Ex: My XML looks as follows

<Root>
  <Parent id="1">
    <Child id="1" />
    <Child id="2" />
    <Child id="3" />
  </Parent>
  <Parent id="2">
    <Child id="1" />
    <Child id="2" />
    <Child id="3" />
  </Parent>
  <Parent id="3">
    <Child id="1" />
    <Child id="2" />
    <Child id="3" />
  </Parent>
</Root>

My background is .NET & XPATH traversing is very easier with System.XML

I am working on a (new to) Java application where I need to use XML. I am planning to use JDOM2. I want to use DOM parsing and not SAX.

I am looking for some examples on how to use XPATH with JDOM2.

Ex. How can I navigate to an element let's say "/Root/Parent[@id='2']/Child[@id='3']"

Can you guys give me some examples? I searched but I couldn't find one for JDOM2


回答1:


Ok, found this https://github.com/hunterhacker/jdom/wiki/JDOM2-A-Primer and seem to be helpful




回答2:


Here is an example of JDOM2 XPATH



来源:https://stackoverflow.com/questions/15541652/looking-for-jdom2-xpath-examples

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!