Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
跳过PHP XPath中的值_Php_Xml_Xpath - Fatal编程技术网

跳过PHP XPath中的值

跳过PHP XPath中的值,php,xml,xpath,Php,Xml,Xpath,我正在使用PHPxpath从XML读取值。我有下面这样的条件,我想获得“a”的Id,其中“b”中只有名称标签。如果有任何其他标记与名称一起出现,则跳过。预计产量为1。但是我得到了标记的所有ID。我正在使用Xpath作为 $xml->xpath("//a[b/name = 'value1' ]/@id"); 如何跳过ID 2和3并获得输出1 示例XML <a id="1"> <b> <name> value1 </name

我正在使用
PHP
xpath
XML
读取值。我有下面这样的条件,我想获得“a”的Id,其中“b”中只有名称标签。如果有任何其他标记与名称一起出现,则跳过。预计产量为1。但是我得到了标记的所有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
价值1
价值2
价值1
价值3
试试这个:

//a/b[count(*)=1,count(name)=1]/../id