2

我有以下xml(实际上更长)

    <excluded_postcodes>
   <postcode Outward="TR1">
    <Inward>1DH</Inward>
    <Inward>1DQ</Inward><
    Inward>1DW</Inward>
    <Inward>1DZ</Inward>
    <Inward>1EP</Inward>
    <Inward>1ET</Inward>
    <Inward>1EU</Inward>
    <Inward>1EX</Inward>
       </postcode>
       <postcode Outward="TR1">
            <Inward>1PT</Inward>
    <Inward>1QA</Inward>
    <Inward>1QH</Inward>
    <Inward>1SE</Inward>
    <Inward>1SG</Inward>
       </postcode>
    </excluded_postcodes>

我可以使用 simplexml xpaths 匹配给定外部值的邮政编码

$xml->xpath('/excluded_postcodes/postcode[@Outward="TR1"]');

我想做的是匹配 postode[@Outward="TR1"] 的给定 Inward Value 的孩子

$xml->xpath('/excluded_postcodes/postcode[@Outward="TR1"]/Inward//text()="1EU"');

但是我没有运气尝试建立正确的 xpath 来实现这一点。非常感谢任何帮助。

谢谢

4

1 回答 1

2
/excluded_postcodes/postcode[@Outward="TR1"]/Inward[text()="1EU"]
于 2012-11-12T12:22:21.013 回答