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. Android逆向笔记之AndroidKiller与Android Studio的使用

    https://blog.csdn.net/a_1054280044/article/details/60465267 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog. ...

  2. 【mac】php7.1 安装swoole 扩展

    环境依赖: php- 或更高版本 gcc-4.4 或更高版本 make autoconf 下载源代码包后,在终端进入源码目录,执行下面的命令进行编译和安装 https://github.com/swo ...

  3. 【咸鱼教程】本地图片上传。动态GIF表情图生成

    本案例参考:http://emoji.decathlon.trustingme.cn/但是实现方式不一样. 教程目录一 head first二 打开本地图片功能三 拖拽和缩放手势,调整图片四 gifj ...

  4. jmeter聚合报告导出时乱码的解决

    在使用jmeter性能测试时,聚合报告导出后使用excel打开时是乱码,查看相关文件后是编码的问题,解决方法如下: 1.现象: 用excel打开变成这种乱码无法看清 2.解决: 先使用记事本打开后,选 ...

  5. node中非常重要的process对象,Child Process模块

    node中非常重要的process对象,Child Process模块Child Process模块http://javascript.ruanyifeng.com/nodejs/child-proc ...

  6. 经典把妹桥段:Flower dance开头对话

    听到一首很赞的钢琴曲,Flower Dance,其开头有一段英文对话,如下: Lucy:"They serve the purpose of changing hydrogen into b ...

  7. Flask详解

    Flask是一个基于Python开发并且依赖jinja2模板和Werkzeug WSGI服务的一个微型框架,对于Werkzeug本质是Socket服务端,其用于接收http请求并对请求进行预处理,然后 ...

  8. Navicat 同步数据库中数据

     Navicat工具同步两个数据库中的数据 第一步在我们的电脑里面打开navicat软件,打开要复制表的数据库,如下图所示:   第二步点击上方的“工具->数据传输”,如下图所示:   第三步进 ...

  9. Eigen中的基本函数 及其对应的matlab函数

    原文地址C++矩阵库 Eigen 快速入门 不仅有函数的基本形式,还有对应的matlab函数,用起来很方便. Eigen 矩阵定义 #include <Eigen/Dense> Matri ...

  10. opencv学习之PyImageSearch

    Practical Python and OpenCV+ Case Studies 是一本opencv的入门书籍 强烈推荐一个老外的网站,pyimagesearch 网址:https://www.py ...