选择一系列节点的 XPath 是什么? [英] What is the XPath to select a range of nodes?
本文介绍了选择一系列节点的 XPath 是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个结构如下的 XML 文件:
I have an XML file that's structured like this:
<foo>
<bar></bar>
<bar></bar>
...
</foo>
我不知道如何抓取一系列节点.有人能给我一个 XPath 表达式的例子,它可以抓取 100-200 个条形节点吗?
I don't know how to grab a range of nodes. Could someone give me an example of an XPath expression that grabs bar nodes 100-200?
推荐答案
使用:
/*/bar[position() >= 100 and not(position() > 200)]
请注意:
正好选择位置 100 到 200(含)的
bar
元素.
对这个 XPath 表达式的求值可能比使用 //
缩写的表达式快很多倍,因为后者会导致对以上下文节点为根的树进行完整扫描.在可能的情况下,始终尽量避免使用 //
缩写.
The evaluation of this XPath expressions can be many times faster than an expression using the //
abbreviation, because the latter causes a complete scan of the tree whose root is the context node. Always try to avoid using the //
abbreviation in cases when this is possible.
这篇关于选择一系列节点的 XPath 是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文