2009-07-10 14 views
0

は私が検索しようとしているいくつかのXMLがあります。基本的に属性を使用した複雑なXPath検索?

<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> 

を、私が何をしようとしていますどのような、非常に可能性がありませんこれは(セクションYYYYYの下に座って、アカウントのすべてのノードを見つけることですそのレベルのノードのみ)。私は(特に私はRailsの上Hpricotを使用しています)のXPathでこれを行うことができますどのように

答えて

3

これを試してみてください。

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

http://www.bit-101.com/xpath/は、XPathクエリをテストするための便利なツールを持っています。

+0

+1 - 完全性のために:これは 'YYYYY'の説明を持つ* all *セクションノード内のすべてのアカウントノードを見つけます。 – Tomalak

関連する問題