Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 使用属性的复杂XPath搜索?_Xml_Xpath - Fatal编程技术网

Xml 使用属性的复杂XPath搜索?

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

我尝试搜索一些XML:

<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”的节节点中的所有帐户节点。