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轴方式,可根据文档中元素的相对位置,来进行元素的定位.例如:先找到一个相对好定位的元素,在根据与 ...
随机推荐
- 【cs229-Lecture3】Logistic回归
参考: http://www.itongji.cn/article/12112cH013.html http://blog.csdn.net/zouxy09/article/details/20319 ...
- python tkinter Listbox用法
python tkinter组件的Listbox的用法,见下面代码的演示: from tkinter import * root=Tk() v=StringVar() #Listbox与变量绑定' l ...
- 阅读代码工具:Visual Studio Code
打开一个文件夹,直接阅读,体验还不错 版本: 1.25.1提交: 1dfc5e557209371715f655691b1235b6b26a06be日期: 2018-07-11T15:43:11.471 ...
- Storm启动流程分析
1. 客户端运行storm nimbus时,会调用storm的python脚本,该脚本中为每个命令编写一个方法,每个方法都可以生成一条相应的java命令. 命令格式如下:java -server xx ...
- nginx expires配置
配置expiresexpires起到控制页面缓存的作用,合理的配置expires可以减少很多服务器的请求要配置expires,可以在http段中或者server段中或者location段中加入 1 ...
- BZOJ3163&Codevs1886: [Heoi2013]Eden的新背包问题[分治优化dp]
3163: [Heoi2013]Eden的新背包问题 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 428 Solved: 277[Submit][ ...
- 关于spring中的事件体系
在客户这边上班,平时做开发的时候用到了一个客户自己写的一个开发框架,和spring类似,就是功能少一点,提供了依赖注入,事件体系,任务执行等常用的功能,还提供了一个桥接器,可以把spring中的bea ...
- 二手回收能否翻过BAT这座大山?
自2015年几大合并事件后,互联网江山基本都归于BAT三家.即便近日战火熊熊的本地生活和外卖也都是百度.阿里和腾讯的家门事.创业浪潮在2015年疯狂过后,留给下一年的风口似乎不多了. 不过有媒体预测智 ...
- 从Java代码到字节码(1)
理解Java代码是如何被编译为字节码并在Java虚拟机(JVM)上执行是非常重要的,这将帮助理解你的程序是如何执行的.这样的理解不仅仅能够让你在逻辑上更好的掌握语言特性,而且能够有机会理解在做出重要决 ...
- ios三张图片组合一张
- (UIImage *)addImage:(UIImage *)image1 toImage:(UIImage *)image2 { UIGraphicsBeginImageContext(imag ...