我有以下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”]给定内向值的子级

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


但是我没有运气试图建立正确的xpath来实现这一目标。
任何帮助,不胜感激。

谢谢

最佳答案

/excluded_postcodes/postcode[@Outward="TR1"]/Inward[text()="1EU"]

10-06 03:55