tags:

views:

39

answers:

1

I have some XML which I'm trying to search:

<debts>
     <section id="24" description="YYYYY">
     <section id="28" description="xxx">
      <section id="31" description="xxx">
       <account accountNumber="2312323" creditorId="1" amount="1200" proposedAmount="1000" percentage="11" owner="2">
        <foo/>
       </account>
      </section>
      <section id="32" description="xxx"/>
      <section id="33" description="xxx"/>
     </section>
     <section id="29" description="xxx">
      <section id="34" description="xxx"/>
     </section>
     <section id="30" description="xxx">
      <section id="37" description="xxx"/>
      <section id="38" description="xxx"/>
      <section id="39" description="xxx"/>
     </section>
    </section>
</debts>

Essentially, what I am trying to do, is find all of the account nodes that sit underneath the section YYYYY (which is quite likely not the only node at that level). How can I do this with XPath (specifically I'm using Hpricot on Rails)

+2  A: 

try this:

/debts//section[@description='YYYYY']//account

http://www.bit-101.com/xpath/ has a nice tool to test xpath queries.

Josh
+1 - For the sake of completeness: This finds all account nodes within *all* section nodes that have a description of 'YYYYY'.
Tomalak