This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes XPath Parent Node Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XPath Parent Node Problem" Watch "XPath Parent Node Problem" New topic
Author

XPath Parent Node Problem

Jonathan Cook
Greenhorn

Joined: Nov 11, 2007
Posts: 1
Hello,

I have the following xml:

<?xml version="1.0" encoding="UTF-8"?><horseRacingResults>
<meeting id="11952" courseName="York" date="20050816">
<race id="94544" runners="18" date="20050816" status="Result">
<horse id="259587" name="Most Definitely" number="1">
<jockey id="17843" name="D Allan"/>
<trainer id="10380" name="T D Easterby"/>
<result finished="false" finishPos="0" disqualified="false"/>
</horse>
<horse id="471752" name="Bay Story" number="2">
<jockey id="2616" name="J Fanning"/>
<trainer id="1883" name="M Johnston"/>
<result finished="false" finishPos="0" disqualified="false"/>
</horse>
<horse id="424305" name="Camrose" number="3">
<jockey id="4035" name="J Fortune"/>
<trainer id="48" name="J L Dunlop"/>
<result finished="true" finishPos="1" disqualified="false"/>
</horse>
</race>
</meeting>
</horseRacingResults>

I would like to select only the horse nodes that have the attribute finished="true". However I would also like those horse node(s) wrapped in the race and meeting nodes which is the part I am having trouble with.

This returns all the horse nodes but doesn't return the race or meeting nodes: //race/horse[result/@finished='true']

I thought I might be able to use this: //meeting[race/horse/result/@finished='true']

or this: //meeting[race/horse/result/@finished='true']|//meeting/race[horse/resul
t/@finished='true']

But this one just seems to return all the horse nodes rather than just the one: I am expecting this result from the above xml:

<meeting id="11952" courseName="York" date="20050816">
<race id="94544" runners="18" date="20050816" status="Result">
<horse id="424305" name="Camrose" number="3">
<jockey id="4035" name="J Fortune"/>
<trainer id="48" name="J L Dunlop"/>
<result finished="true" finishPos="1" disqualified="false"/>
</horse>
</race>
</meeting>

Would really appreciate some help
Thanks.
 
wood burning stoves
 
subject: XPath Parent Node Problem
 
Similar Threads
help creating mutator
Descending order and associating Array Elements in sort method to another's elements
Ajax, Struts, and a few pesky event based issues
Struts 2 JCaptchaforStruts 2 issue
Spotting errors