简体   繁体   English

什么是 。 属性位置的xpath中的(点)?

[英]What is . (dot) in xpath at place of attribute?

At some places, I saw element like following - 在某些地方,我看到了类似以下内容的元素-

//a[.='Assignment']

Generally we've syntax like - //tagName[attributeKey='attributeValue'] or //tagName[text()='textValue'] 通常,我们使用如下语法- //tagName[attributeKey='attributeValue']//tagName[text()='textValue']

But what is intention of . 但是的目的是什么. in xpath //a[.='Assignment'] ? 在xpath中//a[.='Assignment']吗?

I'll use XPath 2.0 terminology here: XPath 1.0 has different terminology but the effect of the expression is the same. 我将在这里使用XPath 2.0术语:XPath 1.0具有不同的术语,但是表达式的效果是相同的。

"." “。” refers to the context item: that is, the a element that you are testing against the predicate. 指的是上下文项:即,您要针对谓词测试a元素。 Its value here is a node. 它的值是一个节点。 When a node is used as an argument of "=", it is atomized , which means (unless your code is schema-aware, which is unlikely) that the string value of the node is compared with the other operand of "=". 当节点用作“ =”的参数时,它被原子化 ,这意味着(除非您的代码具有架构意识,这不太可能)将节点的字符串值与其他操作数“ =”进行比较。 The string value of an element is the concatenation of all its descendant text nodes. 元素的字符串值是其所有后代文本节点的串联。

It sounds like you don't have ready access to an XPath reference. 听起来您尚未准备好访问XPath引用。 There are quite a few good books that cover XPath, there are online tutorials (which are highly variable in quality) and the W3C specification itself (especially for XPath 1.0) is surprisingly easy reading. 有很多关于XPath的好书,有在线教程(质量变化很大),并且W3C规范本身(尤其是XPath 1.0)很容易阅读。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM