博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
XPath轴
阅读量:4656 次
发布时间:2019-06-09

本文共 3233 字,大约阅读时间需要 10 分钟。

XPath 轴

翻译:Linyupark / 2006-03-24

The XML Example Document
XML举例文档

We will use the following XML document in the examples below.

我么将使用该XML文档进行下面的举例说明

Harry Potter
29.99
Learning XML
39.95
 

 


XPath Axes
XPath轴

An axis defines a node-set relative to the current node.

轴定义了相对于当前节的节集

轴名 结果
ancestor Selects all ancestors (parent, grandparent, etc.) of the current node[选择了当前节的所有祖(父,祖父,等等)]
ancestor-or-self Selects all ancestors (parent, grandparent, etc.) of the current node and the current node itself[选择当前节的所有祖并且还有当前节自己]
attribute Selects all attributes of the current node[选择所有当前节的属性]
child Selects all children of the current node[选择所有当前节的子]
descendant Selects all descendants (children, grandchildren, etc.) of the current node[选择所有当前节的孙(子,孙子,等等)]
descendant-or-self Selects all descendants (children, grandchildren, etc.) of the current node and the current node itself[选择当前节的所有孙以及它本身]
following Selects everything in the document after the closing tag of the current node[选择所有在关闭当前节标签后的所有内容]
following-sibling Selects all siblings after the current node[选择所有当前节后的兄]
namespace Selects all namespace nodes of the current node[选择所有当前节的命名空间]
parent Selects the parent of the current node[选择当前节的父]
preceding Selects everything in the document that is before the start tag of the current node[选择当前节之前的所有内容]
preceding-sibling Selects all siblings before the current node[选择所有当前节之前的兄]
self Selects the current node[选择当前节]

 


Location Path Expression
路径表达试定位

A location path can be absolute or relative.

定位路径可以是绝对的也可以是相对的

An absolute location path starts with a slash ( / ) and a relative location path does not. In both cases the location path consists of one or more steps, each separated by a slash:

绝对定位的路径由(/)开始,而相对定位就不这样。定位的路径由一个或多个步骤所组成,每部分由(/)相分隔:

An absolute location path:
/step/step/...
A relative location path:
step/step/...

Each step is evaluated against the nodes in the current node-set.

在当前的节集中每步的赋值是逆向的

A step consists of:

  • an axis (defines the tree-relationship between the selected nodes and the current node)
  • a node-test (identifies a node within an axis)[在轴中鉴定节]
  • zero or more predicates (to further refine the selected node-set)[0个或多个谓语可以来更好的选择节]

The syntax for a location step is:

定位的语法

axisname::nodetest[predicate]

Examples
实例

Example 结果
child::book Selects all book nodes that are children of the current node[选择当前节点下所有为book的子节点]
attribute::lang Selects the lang attribute of the current node[选择当前节点下所有属性为lang的内容]
child::* Selects all children of the current node[选择当前节下所有的子节]
attribute::* Selects all attributes of the current node[选择当前节所有的属性]
child::text() Selects all text child nodes of the current node[选择当前节点所有子节点的文字]
child::node() Selects all child nodes of the current node[选择所有当前节点的子节点]
descendant::book Selects all book descendants of the current node[选择当前节点所有为book的孙节点]
ancestor::book Selects all book ancestors of the current node[选择所有当前祖节点为book的节点]
ancestor-or-self::book Selects all book ancestors of the current node - and the current as well if it is a book node[当前节点和其祖节点为book的节点]
child::*/child::price Selects all price grandchildren of the current node[当前节点所有含price的孙子节点]

转载于:https://www.cnblogs.com/yanzi-meng/p/8871202.html

你可能感兴趣的文章
Java内部类详解
查看>>
初识Twisted(一)
查看>>
linux 软件安装篇
查看>>
Sql server数据库大小写敏感设置
查看>>
JAVA多线程-内存模型、三大特性、线程池
查看>>
RxJS速成 (下)
查看>>
无锁栈与无锁队列
查看>>
微信开发第8章 通过accesstoken将长连接转换为短链接
查看>>
[刷题]Codeforces 785D - Anton and School - 2
查看>>
四川红油的制法
查看>>
Java重写《C经典100题》 --21
查看>>
【Android基础】Fragment 详解之Fragment生命周期
查看>>
链表(裸题)
查看>>
11运算符重载
查看>>
磁盘系统的管理
查看>>
C/S
查看>>
Http Get/Post请求的区别
查看>>
STM32一键下载电路设计原理
查看>>
C语言中函数返回字符串的四种方法
查看>>
10月区块链领域投融资事件盘点
查看>>