XPath轴中的子代,后代和后代之间的差异 [英] Difference between child, following and descendant in XPath axes

查看:55
本文介绍了XPath轴中的子代,后代和后代之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我所了解的是

  1. :: child 查找当前节点的直接子注释
  2. :: following 查找当前节点的直接子级和子级子级等等.
  3. 那么什么是 :: descendant ?

有人可以通过简单的例子帮助我理解吗?

解决方案

  • child :: 将选择上下文节点的直接后代,但不会像 descendant :: 那样深入.
  • following :: 将选择所有在上下文节点及其后代之后的节点,但不包括上下文节点的后代.
  • descendant :: 将选择沿 child :: 轴的所有节点,以及它们的子代和子代的子代,等等.

有时候,一张图片值一千字:

图片来源,请参见图3.5

使用XPath可视化工具可能会有所帮助,以便根据一些示例XML评估XPath表达式,并查看选择了什么和未选择什么.

例如: http://chris.photobooks.com/xml

Till now what all I understand is

  1. ::child looks for immediate child notes of the current node
  2. ::following looks for immediate child and sub child and so on of the current node.
  3. 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, like descendant:: 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 the child:: axis, as well as their children, and their children's children, etc..

Sometimes, a picture is worth a thousand words:

Image source, see Figure 3.5

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆