Xml 使用属性的复杂XPath搜索?
我尝试搜索一些XML:Xml 使用属性的复杂XPath搜索?,xml,xpath,Xml,Xpath,我尝试搜索一些XML: <debts> <section id="24" description="YYYYY"> <section id="28" description="xxx"> <section id="31" description="xxx"> <account accountNumber="2312323" creditorId="1" a
<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节下面的所有帐户节点(很可能不是该级别的唯一节点)。如何使用XPath实现这一点(特别是我在Rails上使用Hpricot)尝试以下方法:
/debts//section[@description='YYYYY']//account
有一个很好的工具来测试xpath查询。试试这个:
/debts//section[@description='YYYYY']//account
有一个很好的工具来测试xpath查询。+1-为了完整性:这将查找所有描述为“yyyy”的节节点中的所有帐户节点。+1-为了完整性:这将查找所有描述为“yyyy”的节节点中的所有帐户节点。