如何在 XPath 中使用 AND 运算符? [英] How to use AND operator in XPath?
本文介绍了如何在 XPath 中使用 AND 运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
XML 就像
<a id="1">
<b>value1</b>
<b>value2</b>
</a>
我想编写 XPath 来查找 的 id,其中将有两个
子节点具有固定值
value1
和 value2
.我试图找出具有类似条件的 XPath
I want to write XPath to find id of <a>
where there will be two <b>
child nodes having fix value value1
and value2
. I tried to to find out XPath with condition like
$xml->xpath('*[b=value1] | *[b=value2]');
value1
和 value2
存在于 <b>
节点中,但我无法完全像我第一次使用 XPath 那样得到.
value1
and value2
are present in <b>
node, but I can not get exactly as I am using XPath first time.
推荐答案
下面的XPath,
//a[b = 'value1' and b = 'value2']/@id
将选择所有 a
元素的 id
属性,其中子 b
元素的字符串值等于 value1
AND 另一个子 b
元素的字符串值等于请求的 value2
.
will select id
attributes of all a
elements with a child b
element having string value equal to value1
AND another child b
element having string value equal to value2
as requested.
这篇关于如何在 XPath 中使用 AND 运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文