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轴的更多相关文章

  1. xpath轴的正确使用姿势

    网上看了许多关于轴的介绍,只介绍了语法,而没有明说具体实际中该怎么使用,百思不得其解. 背景--python中使用xpath:  ----------------------------------- ...

  2. XPath 轴

    XML 实例文档 我们将在下面的例子中使用此 XML 文档: <?xml version="1.0" encoding="ISO-8859-1"?> ...

  3. python+selenium基础之XPATH轴定位(第二篇)

    第一篇讲了xpath定位的一些基本定位方法,这里再介绍一种:xpath轴定位,应用场景是当某个元素的各个属性及其组合都不足以定位时,那么可以利用其兄弟节点或者父节点等各种可以定位的元素进行定位. 1. ...

  4. XPath轴(XPath Axes)总结

    XPath轴(XPath Axes)可定义某个相对于当前节点的节点集: 1.child 选取当前节点的所有子元素 2.parent 选取当前节点的父节点 3.descendant 选取当前节点的所有后 ...

  5. selenium中Xpath轴定位方法

    1.Xpath轴:轴可定义相对于当前节点的节点集. 使用语法:轴名称::节点名称 例://input[@data-value="SXRYNAME"]/parent::td/foll ...

  6. 深入浅出xpath轴定位

    在web自动化里面经常要用到定位,常用的八种定位方式中我最喜欢xpath定位,功能很强大.结合它里面的文本定位.模糊定位.逻辑定位等,基本能搞定所有的元素定位问题. 今天要讨论的是xpath的另一种比 ...

  7. 了解XPath与XPath轴

    XPath 是一门在 XML 文档中查找信息的语言.XPath 用于在 XML 文档中通过元素和属性进行导航. 节点(Node) 在 XPath 中,有七种类型的节点:元素.属性.文本.命名空间.处理 ...

  8. web-UI自动化必会技能—xpath轴,了解一下?

    本来以为不会再更新UI自动化相关的东西了,不过最近群里的朋友在搞UI,提出了许多问题,我看了下,大多还是页面元素定位类的问题,那今天就再讲点. 一.先了解xpath 说到元素定位,大家应该都知道常见的 ...

  9. 『心善渊』Selenium3.0基础 — 7、XPath轴定位详解

    目录 1.XPath轴定位介绍 2.位置路径表达式概念 3.步的路径表达式范例 4.练习 使用XPath轴方式,可根据文档中元素的相对位置,来进行元素的定位.例如:先找到一个相对好定位的元素,在根据与 ...

随机推荐

  1. 【cs229-Lecture2】Linear Regression with One Variable (Week 1)(含测试数据和源码)

    从Ⅱ到Ⅳ都在讲的是线性回归,其中第Ⅱ章讲得是简单线性回归(simple linear regression, SLR)(单变量),第Ⅲ章讲的是线代基础,第Ⅳ章讲的是多元回归(大于一个自变量). 本文的 ...

  2. sqlserver服务器名称改成本地IP地址登录

    在安装sqlserver2008.2012等时选择的是默认实例,服务器名称也就是电脑的名称,特别是登录本地的数据库,需要输入电脑用户名称加上SQLEXPRESS 例如:zhangsan\SQLEXPR ...

  3. js 的空值判断程序

    function empty(v){ switch (typeof v){ case 'undefined' : return true; case 'string' : if($.trim(v).l ...

  4. NC 的高级应用

    高级用法: (1)作攻击程序用,例子: 格式1:type.exe c:\exploit.txt|nc -nvv 192.168.x.x 80 格式2:nc -nvv 192.168.x.x 80 &l ...

  5. Elasticsearch学习之深入聚合分析一---基本概念

    首先明白两个核心概念:bucket和metric 1. bucket:一个数据分组 city name 北京 小李 北京 小王 上海 小张 上海 小丽 上海 小陈 基于city划分buckets,划分 ...

  6. sencha touch 评分扩展

    原版 :https://market.sencha.com/extensions/sencha-touch-2-rating-star-field 效果: 我的改造版(只是类名变了): Ext.def ...

  7. Telnet是什么意思又是什么协议 Telnet有什么作用及功能

    Telnet是teletype network的缩写,专业的说,Telnet是Internet上远程登录的一种程序:它可以让您的电脑通过网络登录到网络另一端的电脑上,甚至还可以存取那台电脑上的文件. ...

  8. CF 217A Ice Skating

    A. Ice Skating time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  9. 虚拟机VMware怎么完全卸载干净,如何彻底卸载VMware虚拟机

    亲测好使. 1.禁用VM虚拟机服务 首先,需要停止虚拟机VMware相关服务.按下快捷键WIN+R,打开windows运行对话框,输入[services.msc],点击确定.如下图. 在服务管理中,找 ...

  10. 【JSP】JSP的介绍和基本原理

    JSP简介 JSP的核心实质是Servlet技术.JSP是后来添加的基于Servlet的一种扩展技术.但二者在使用上有不同的方向. 由于Servlet实质是一个Java类,因此非常适合用来处理业务逻辑 ...