[英]What is the difference between //*[*] and //*[.] in XPath?
I am trying to understand the difference between我试图理解两者之间的区别
//*[.] and //*[*]
These return different number of elements.这些返回不同数量的元素。
Also where I can use the dot instead of attribute还有我可以使用点而不是属性的地方
//tag[@Attribute="value"]
Not just in case of text?不只是在文本的情况下? And what does the syntax look like?
语法是什么样的? Because I tried
因为我试过了
//tag[@.="value"] and //tag[.="value"]
and the last one only worked in case of text but not instead of case最后一个只适用于文本,而不适用于大小写
//tag[@id="value"]
for example, so when can I change the dot instead of attribute?例如,我什么时候可以更改点而不是属性?
//*[.]
will select all elements. //*[.]
将选择所有元素。 It is equivalent to //*
.它相当于
//*
。
//*[*]
will select all elements that have at least one child element. //*[*]
将选择至少有一个子元素的所有元素。
//tag[@.="value"]
is syntactically invalid. //tag[@.="value"]
在语法上无效。
//tag[.="value"]
will select all tag
elements whose string value equals value
. //tag[.="value"]
将选择字符串值等于value
所有tag
元素。 For example, for this XML,例如,对于这个 XML,
<tag id="r">
<tag id="a">value</tag>
<tag id="b">val<br/>ue</tag>
<tag id="c"><span>val</span><span>ue</span></tag>
<tag id="f"> value</tag>
<tag id="g">Value</tag>
</tag>
//tag[.="value"]
will select //tag[.="value"]
将选择
<tag id="a">value</tag>
<tag id="b">val<br/>ue</tag>
<tag id="c"><span>val</span><span>ue</span></tag>
See also Testing text() nodes vs string values in XPath另请参阅在 XPath 中测试 text() 节点与字符串值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.