• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XPath Parent Node Problem

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic