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. php文件的处理和操作

    好长时间没有看php手册了,有些关于文件操作方面的知识点发现从没有学过,现补习一下,顺便整理一下: 1.文件的打开:fopen()   此函数的第一个参数含有要打开的文件的名称,第二个参数规定了使用哪 ...

  2. 【H5】使用h5实现复制粘贴功能

    方案一 : 可满足大部分浏览器正常使用 <!DOCTYPE html> <html lang="en"> <head> <meta cha ...

  3. 【python3】 django2.0 在生成数据库表时报错: TypeError: __init__() missing 1 required positional argument: 'on_delete'

    python: 3.6.4 django: 2.0 models.py 代码如下 # coding: utf-8 from django.db import models from django.co ...

  4. 通过orderby关键字,LINQ可以实现升序和降序排序。LINQ还支持次要排序。

    通过orderby关键字,LINQ可以实现升序和降序排序.LINQ还支持次要排序. LINQ默认的排序是升序排序,如果你想使用降序排序,就要使用descending关键字. static void M ...

  5. 电子邮件 -- 图解TCP_IP_第5版

    图解TCP_IP_第5版 作者: [日]竹下隆史 / [日]村山公保 / [日]荒井透 / [日]苅田幸雄 出版社: 人民邮电出版社原作名: マスタリングTCP/IP 入門編 第5版译者: 乌尼日其其 ...

  6. JVM垃圾收集器组合--各种组合对应的虚拟机参数实践

    前言 相信很多人都看过下面这张图,(来自<深入理解Java虚拟机:JVM高级特性与最佳实践>) 在学完几种垃圾收集器类型及组合后,打算看看实际中程序用到的垃圾收集器. 但是在jconsol ...

  7. Windows系统的文件浏览器如何触发刷新

    最近开发一个Drive程序,修改注册表添加System Folder Drive后需要通知已打开的每个文件浏览器刷新.最初选择获取对应窗体的句柄并发送WM_KEYDOWN.WM_KEYUP的VK_F5 ...

  8. Android LayoutCast 初探

    今天无意间看见了一个神器,顿时让我血气蓬勃! 废话不多说,先上网址:https://github.com/mmin18/LayoutCast 把代码和资源文件的改动直接同步到手机上,应用不需要重启.省 ...

  9. SOA架构商城一

    SOA架构: SOA是Service-Oriented Architecture的首字母简称,它是一种支持面向服务的架构样式.从服务.基于服务开发和服务的结果来看,面向服务是一种思考方式.其实SOA架 ...

  10. 在sublime中安装使用TortoiseSVN-sublime使用心得(4)

    通过sublime text 2.0 安装 TortoiseSVN 插件. 和其它插件不同的是,安装成功后,重启sublime text 2.0 ,在Preferences->Package S ...