我有以下 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"]');
我想做的是匹配给定的后置值的子节点[@Outward="TR1"]
$xml->xpath('/excluded_postcodes/postcode[@Outward="TR1"]/Inward//text()="1EU"');
但是我没有运气尝试建立正确的 xpath 来实现这一点。 非常感谢任何帮助。
谢谢
最佳答案
/excluded_postcodes/postcode[@Outward="TR1"]/Inward[text()="1EU"]
关于php simplexml xpath按属性匹配元素并按文本值匹配子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13343450/