跳过PHP XPath中的值

时间:2016-10-24 06:49:41

标签: php xml xpath

我正在使用PHP xpath来阅读XML中的值。我有以下条件,我希望获得“a”的ID,其中“b”中只有名称标签。并且如果任何其他标记与名称一起出现则跳过。预期输出为1.但我得到了“a”标签的所有ID。我使用Xpath作为

$xml->xpath("//a[b/name = 'value1' ]/@id"); 

我如何跳过id 2和3并获得输出1

示例XML

<a id="1">
    <b>
        <name> value1 </name>
    </b>
</a>
<a id="2">
    <b>
        <name> value1 </name>
        <other> value2 </other>
    </b>
</a>
<a id="3">
    <b>
        <name> value1 </name>
        <other> value3 </other>
    </b>
</a>

1 个答案:

答案 0 :(得分:2)

试试这个:

CORRECT URL 3 CORRECT URL 4 CORRECT URL 5 URL FROM IFRAME AFTER THAT BUT THAT WAS NOT IN THE LIST 1 URL FROM IFRAME AFTER THAT BUT THAT WAS NOT IN THE LIST 2