Joh*_*n K 35 xml xpath elements
除特定元素名称外,如何定位文档中的所有元素?
例如,我想排除terminate元素.它们可以在整个文档中出现.
<root>
<terminate attr="1" />
<other>
The brown fox jumps over the fence.
<terminate>
<b>stuff</b>
</terminate>
</other>
</root>
Run Code Online (Sandbox Code Playgroud)
我尝试使用not(..)运算符没有成功,因为我使用它错了.
坦率地说谷歌'不'是艰难的!
Jag*_*mag 53
以下xpath应该可以工作
/root/*[not(self::terminate)]
Run Code Online (Sandbox Code Playgroud)
此外,我认为你也可以这样做
/root/*[not(name()='terminate')]
Run Code Online (Sandbox Code Playgroud)
如果您使用的是 XPath 2.0,您可以使用
/root/* except /root/terminate
Run Code Online (Sandbox Code Playgroud)
这正如你所期望的那样。它匹配第一个序列中存在但不存在第二个序列中的节点。
| 归档时间: |
|
| 查看次数: |
30811 次 |
| 最近记录: |