XPath轴中的子代,后代和后代之间的差异 [英] Difference between child, following and descendant in XPath axes
本文介绍了XPath轴中的子代,后代和后代之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在我所了解的是
-
:: child
查找当前节点的直接子注释 -
:: following
查找当前节点的直接子级和子级子级等等. - 那么什么是
:: descendant
?
有人可以通过简单的例子帮助我理解吗?
解决方案
-
child ::
将选择上下文节点的直接后代,但不会像descendant ::
那样深入. -
following ::
将选择所有在上下文节点及其后代之后的节点,但不包括上下文节点的后代. -
descendant ::
将选择沿child ::
轴的所有节点,以及它们的子代和子代的子代,等等.
有时候,一张图片值一千字:
使用XPath可视化工具可能会有所帮助,以便根据一些示例XML评估XPath表达式,并查看选择了什么和未选择什么.
例如: http://chris.photobooks.com/xml
Till now what all I understand is
::child
looks for immediate child notes of the current node::following
looks for immediate child and sub child and so on of the current node.- What is
::descendant
then?
Can anyone help me understand with simple example?
解决方案
child::
will select the immediate descendants of the context node, but does not go any deeper, likedescendant::
does.following::
will select all of the nodes that come after the context node and their descendant's, but that does not include the context node's descendants.descendant::
will select all of the nodes along thechild::
axis, as well as their children, and their children's children, etc..
Sometimes, a picture is worth a thousand words:
It might be helpful to play with an XPath visualization tool, in order to evaluate your XPath expressions against some sample XML and see what is, and what is not, selected.
For example: http://chris.photobooks.com/xml
这篇关于XPath轴中的子代,后代和后代之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文