Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML traversing problem

 
swapnel surade
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm using JDOM for parsing the xml file.To traverse the file I have used for loop.
Is there any other parser which will give me the feature so that I dont have to traverse the file for searching the node.
for e.g

<bottombar>
<states>
<state name="main">
<sometag1>
<sometag2>
</state>
<state name="sub">
<sometag1>
<sometag2>
</state>
</states>
</bottombar>

as you can see the XML if I want to traverse the states children then I have to apply for loop so that I can get the required tag.
But I want a way by which if i gave "name" of the state then I should get that element.

thanks.


 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what XPath is for. To use it, you don't need any extra library - it comes as part of the JRE in the javax.xml.xpath package. The XmlFaq links to a couple of XPath introductions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic