XPath轴
XPath 轴
翻译:Linyupark / 2006-03-24
The XML Example Document
XML举例文档
We will use the following XML document in the examples below.
我么将使用该XML文档进行下面的举例说明
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book>
<title lang="eng">Harry Potter</title>
<price>29.99</price>
</book>
<book>
<title lang="eng">Learning XML</title>
<price>39.95</price>
</book>
</bookstore>
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的孙子节点] |
XPath轴的更多相关文章
- xpath轴的正确使用姿势
网上看了许多关于轴的介绍,只介绍了语法,而没有明说具体实际中该怎么使用,百思不得其解. 背景--python中使用xpath: ----------------------------------- ...
- XPath 轴
XML 实例文档 我们将在下面的例子中使用此 XML 文档: <?xml version="1.0" encoding="ISO-8859-1"?> ...
- python+selenium基础之XPATH轴定位(第二篇)
第一篇讲了xpath定位的一些基本定位方法,这里再介绍一种:xpath轴定位,应用场景是当某个元素的各个属性及其组合都不足以定位时,那么可以利用其兄弟节点或者父节点等各种可以定位的元素进行定位. 1. ...
- XPath轴(XPath Axes)总结
XPath轴(XPath Axes)可定义某个相对于当前节点的节点集: 1.child 选取当前节点的所有子元素 2.parent 选取当前节点的父节点 3.descendant 选取当前节点的所有后 ...
- selenium中Xpath轴定位方法
1.Xpath轴:轴可定义相对于当前节点的节点集. 使用语法:轴名称::节点名称 例://input[@data-value="SXRYNAME"]/parent::td/foll ...
- 深入浅出xpath轴定位
在web自动化里面经常要用到定位,常用的八种定位方式中我最喜欢xpath定位,功能很强大.结合它里面的文本定位.模糊定位.逻辑定位等,基本能搞定所有的元素定位问题. 今天要讨论的是xpath的另一种比 ...
- 了解XPath与XPath轴
XPath 是一门在 XML 文档中查找信息的语言.XPath 用于在 XML 文档中通过元素和属性进行导航. 节点(Node) 在 XPath 中,有七种类型的节点:元素.属性.文本.命名空间.处理 ...
- web-UI自动化必会技能—xpath轴,了解一下?
本来以为不会再更新UI自动化相关的东西了,不过最近群里的朋友在搞UI,提出了许多问题,我看了下,大多还是页面元素定位类的问题,那今天就再讲点. 一.先了解xpath 说到元素定位,大家应该都知道常见的 ...
- 『心善渊』Selenium3.0基础 — 7、XPath轴定位详解
目录 1.XPath轴定位介绍 2.位置路径表达式概念 3.步的路径表达式范例 4.练习 使用XPath轴方式,可根据文档中元素的相对位置,来进行元素的定位.例如:先找到一个相对好定位的元素,在根据与 ...
随机推荐
- 开机出现checking file system on C怎么办
开机出现checking file system on C怎么办 | 浏览:16126 | 更新:2018-02-04 13:51 | 标签:开机 百度经验:jingyan.baidu.com 开机出 ...
- php pear包打包方法
一)首先下载工具onion 浏览器打开,服务器上wget测试无法正常下载 地址:https://raw.github.com/c9s/Onion/master/onion 二)在临时目录下,建立相关目 ...
- <转>python字典排序 关于sort()、reversed()、sorted()
一.Python的排序 1.reversed() 这个很好理解,reversed英文意思就是:adj. 颠倒的:相反的:(判决等)撤销的 print list(reversed(['dream','a ...
- 【IE兼容问题】记一次Manifest因为jquery版本不同导致的兼容问题解决方案X-UA-Compatible
最近在调试一个jquery插件Manifest 测试过程中发现IE一直不能完全展示这个插件,只显示了一个textbox文本框 IE下的bug的效果图 其他浏览器正常的效果图 跟踪原因,IE下jquer ...
- 【调试错误】找不到 System.Web.Mvc 引用
今天调试新项目,从svn上clone下来,发现运行不了. System.Web.Mvc 显示黄色叹号 解决方案如下: 安装一个 MVC 的插件.AspNetMVC2_VS2008.exe 下载地址:h ...
- WP8.1学习系列(第二十五章)——控件样式
XAML 框架提供许多自定义应用外观的方法.通过样式可以设置控件属性,并重复使用这些设置,以便保持多个控件具有一致的外观. 路线图: 本主题与其他主题有何关联?请参阅: 使用 C# 或 Visua ...
- 转载:C/C++关于string.h头文件和string类
学习C语言时,用字符串的函数例如stpcpy().strcat().strcmp()等,要包含头文件string.h 学习C++后,C++有字符串的标准类string,string类也有很多方法,用s ...
- mysql配置文件my.cnf模板
[client] default-character-set = utf8mb4 port = PORT socket = /srv/myPORT/run/mysql.sock [mysqld] us ...
- vue使用sass
一.安装sass依赖包 $ npm install sass-loader --save-dev //sass-loader依赖于node-sass $ npm install node-sass - ...
- CentOS 配置Rails开发环境
1 安装mysql yum install -y mysql mysql-server 启动mysql $ /etc/init.d/mysqld start 设置root密码,删除test数据库等 / ...