This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Reading XML node attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Reading XML node attribute" Watch "Reading XML node attribute" New topic

Reading XML node attribute

uday kantt

Joined: May 05, 2011
Posts: 26

The following is the XML file
<Student id=10>
<qualification status="failed">Computer Science</qualification>
<Student id=9>
<qualification status="passed">Computer Graphics</qualification>
<Student id=8>
<qualification status="passed">Computer Science</qualification>

So given the above XML file. If the status ="passed" then that particular id of the Student should be fetched into the String variable. Is this possible. Do we have to travel reverse in the XML file. Is this possible. Please Help.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12761
If you are parsing the XML to a DOM (Document Object Model) then you can use the methods in the standard Java library to "move" back from a child Node to a parent Node.

Study the org.w3c.dom.Node JavaDocs

g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 500
This is the xpath for the desired result(s).

ps: Your xml doc is not well-formed at the most basic level. Can you see it?!
I agree. Here's the link:
subject: Reading XML node attribute
Similar Threads
SAX parsing question
how this book is useful to a java programmer !!
xml to java objects
Arrays and strings
struts display properties