gpt4 book ai didi

php - php simplexml xpath按属性匹配元素,按文本值匹配子元素

转载 作者:行者123 更新时间:2023-12-03 16:20:12 24 4
gpt4 key购买 nike

我有以下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"]

关于php - php simplexml xpath按属性匹配元素,按文本值匹配子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13343450/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com