在XPath中,//和.//有什么区别? [英] What is the difference between // and .// in XPath?
问题描述
当我通过google.com在Chrome开发人员工具的控制台上执行这些XPath表达式时,我得到了相同的结果
$ x((.//*[@ id ='gs_lc0']))
$ x((// * [@ id ='gs_lc0']))
XPath中dot的用法是什么?
在bash中, //
和 .//
都是语法缩写: -
//
是/ descendant-or-self :: node()/
-
.//
是self :: node()/ descendant-or-self :: node ()/
对于 对于 简而言之: When I execute these XPath expression on Chrome Developer Tools' console over google.com, I got the same results What is the usage of dot in XPath? In XPath, The For For In short: 这篇关于在XPath中,//和.//有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! //
和 .//
之间的区别在上下文节点中减少了。
//
,上下文节点是根节点; //
是 绝对位置路径 。
.//
,上下文节点取决于上下文; .//
是一个相对位置路径的。在Google Developer Tools控制台的顶级评估中,上下文节点是根节点,因此您会看到相同的结果。
//
文档。
.//
。
$x("(.//*[@id='gs_lc0'])")
$x("(//*[@id='gs_lc0'])")
//
and .//
are both syntactic abbreviations:
//
is short for /descendant-or-self::node()/
.//
is short for self::node()/descendant-or-self::node()/
descendant-or-self
axis contains the context node and all descendents of the context node. So the difference between //
and .//
is reduces to a difference in context nodes.//
, the context node is the root node; //
is an absolute location path..//
, the context node depends upon the context; .//
is a relative location path. At the top-level evaluation in Google Developer Tools console, the context node is the root node, so you'll see identical results.
//
when you wish to select nodes from the entire document..//
when you wish to select nodes only beneath the context node.