`
fly.net.cn
  • 浏览: 183750 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

xpath 语法(节点)

    博客分类:
  • xml
阅读更多
(转自:http://www.w3schools.com/xpath/xpath_nodes.asp)

XPath Nodes

 

In XPath, there are seven kinds of nodes: element, attribute, text, namespace, processing-instruction, comment, and document (root) nodes.


XPath Terminology

Nodes

In XPath, there are seven kinds of nodes: element, attribute, text, namespace, processing-instruction, comment, and document (root) nodes. XML documents are treated as trees of nodes. The root of the tree is called the document node (or root node).

Look at the following XML document:

 
  1. <?xml version="1.0" encoding="ISO-8859-1"?>  
  2.   
  3. <bookstore>  
  4.   
  5. <book>  
  6.   <title lang="en">Harry Potter</title>  
  7.   <author>J K. Rowling</author>   
  8.   <year>2005</year>  
  9.   <price>29.99</price>  
  10. </book>  
  11.   
  12. </bookstore>  

Example of nodes in the XML document above:

 
  1. <bookstore>  (document node)  
  2.   
  3. <author>J K. Rowling</author>  (element node)  
  4.   
  5. lang="en"  (attribute node)  

Atomic values

Atomic values are nodes with no children or parent.

Example of atomic values:

J K. Rowling
"en"

Items

Items are atomic values or nodes.


Relationship of Nodes

Parent

Each element and attribute has one parent.

In the following example; the book element is the parent of the title, author, year, and price:

<book>
xml 代码
 
  1. <book>  
  2.   <title>Harry Potter</title>  
  3.   <author>J K. Rowling</author>  
  4.   <year>2005</year>  
  5.   <price>29.99</price>  
  6. </book>  
<price></price>
</book>

Children

Element nodes may have zero, one or more children.

In the following example; the title, author, year, and price elements are all children of the book element:

<book>
xml 代码
 
  1. <book>  
  2.   <title>Harry Potter</title>  
  3.   <author>J K. Rowling</author>  
  4.   <year>2005</year>  
  5.   <price>29.99</price>  
  6. </book>  

<author></author><price>
</book>

Siblings

Nodes that have the same parent.

In the following example; the title, author, year, and price elements are all siblings:

<book>

xml 代码
 
  1. <book>  
  2.   <title>Harry Potter</title>  
  3.   <author>J K. Rowling</author>  
  4.   <year>2005</year>  
  5.   <price>29.99</price>  
  6. </book>  
<author></author><year></year><price></price>
</book>

Ancestors

A node's parent, parent's parent, etc.

In the following example; the ancestors of the title element are the book element and the bookstore element:

<bookstore></bookstore>
<book><author></author><year></year><price></price>
xml 代码
xml 代码
 
  1. <bookstore>  
  2.   
  3. <book>  
  4.   <title>Harry Potter</title>  
  5.   <author>J K. Rowling</author>  
  6.   <year>2005</year>  
  7.   <price>29.99</price>  
  8. </book>  
  9.   
  10. </bookstore>  

</book>
 

Descendants

A node's children, children's children, etc.

In the following example; descendants of the bookstore element are the book, title, author, year, and price elements:

<bookstore></bookstore>
<book>
<price>
xml 代码
 
  1. <bookstore>  
  2.   
  3. <book>  
  4.   <title>Harry Potter</title>  
  5.   <author>J K. Rowling</author>  
  6.   <year>2005</year>  
  7.   <price>29.99</price>  
  8. </book>  
  9.   
  10. </bookstore>  
</price>
</book>
 
分享到:
评论

相关推荐

    xpath语法与函数

    xpath语法与函数

    XPath语法详解xml开发必备

    对XPath语法进行了详细的讲解。XPath可以快速定位到Xml中的节点或者属性。XPath语法很简单,但是强大够用,它也是使用xslt的基础知识。开发人员必备

    xpath实例语法教程及IBM使用的xpath路径观察器

    同时还提供了IBM等大公司都在使用的xpath操作选择路径的观察器及验证器,该观察器及验证器功能很强大,你只要输入xpath查找路径,验证器会校验语法是否正确,同时会以鲜艳标志显示出xpath所需查找的路径节点。...

    XPath基础用法详解

    xpath简介、教程、Axes、节点、实例、语法、运算符

    Python爬虫基础之XPath语法与lxml库的用法详解

    本来打算写的标题是XPath语法,但是想了一下Python中的解析库lxml,使用的是Xpath语法,同样也是效率比较高的解析方法,所以就写成了XPath语法和lxml库的用法 XPath 即为 XML 路径语言,它是一种用来确定 XML(标准...

    【爬虫学得好,基础少不了】:XPath语法和lxml模块(详解)

    二、xpath helper插件三、xpath helper安装使用方法四、XPath语法4.1 节点语法4.2 节点实例4.3 谓语(Predicates)4.4 选取未知节点4.5 选取若干路径五、XPath 轴5.1 轴常用语法5.2 位置路径表达式5.3 步(step)的...

    xpath 的语法

    解析xml和html的节点语法 用这个语法知识就能非常容易弄懂xml和html的文件并且用系统或第三方的包将其中节点的内容给取出来

    XPath语法20130920

    XPath 使用路径表达式来选取 XML 文档中的节点或节点集。节点是通过沿着路径 (path) 或者步 (steps) 来选取的。

    Java开源的xpath解析器Jsoupxpath.zip

    JsoupXpath 是一款纯Java开发的使用xpath解析html的解析器,xpath语法分析与执行完全独立,html的DOM树生成借助Jsoup,故命名为JsoupXpath.为了在java里也享受xpath的强大与方便但又苦于找不到一款足够强大的xpath...

    Python Xpath 的使用

    文章目录Xpath 的使用lxml 库Xpath 简介Xpath 语法实例应用Xpath 节点所有节点子节点父节点属性单值匹配多值匹配多属性匹配获取属性文本获取Xpath 轴小结 Xpath 的使用 正则表达式 笔记整理 Python requests 模块 ...

    xpath工具zip版本

    XPath即为XML路径语言...XPath基于XML的树状结构,提供在数据结构树中找寻节点的能力。起初XPath的提出的初衷是将其作为一个通用的、介于XPointer与XSL间的语法模型。但是XPath很快的被开发者采用来当作小型查询语言。

    Python的Xpath介绍和语法详解

    2.语法详解 #1.选取节点 ''' / 如果是在最前面,代表从根节点选取,否则选择某节点下的某个节点.只查询子一辈的节点 /html 查询到一个结果 /div 查询到0个结果,因为根节点以下只有一个html子节点 /...

    XPath参考手册.zip

    XPath基于XML的树状结构,提供在数据结构树中找寻节点的能力。起初 XPath 的提出的初衷是将其作为一个通用的、介于XPointer与XSLT间的语法模型。但是 XPath 很快的被开发者采用来当作小型查询语言。

    Python xpath表达式如何实现数据处理

    1. xpath语法 &lt;title lang=eng&gt;Harry Potter&lt;/title&gt; &lt;price&gt;999 &lt;title lang=eng&gt;Learning XML&lt;/title&gt; &lt;price&gt;888 1.1 选取节点 XPath 使用路径表达式来选取 XML 文档中的...

    zyXML解析类模块源码

    3、支持 XPath 语法来查询节点。4、支持 CDATA 。5、开源(如果有任何问题可以自己修改)。缺点:。1、加载速度稍微逊色于支持库,但是查询速度很快。2、不支持DTD,也就是类似于如下的节点。 &lt;!DOCTYPE note [。...

    XML文档查询和转换

    了解XPath的基本语法 能够使用XPath选择节点 能够使用XQuery FLWOR表达式查询XML文档 能够使用XSLT转换简单的XML文档

    PHP操作XML中XPath的应用示例

    起初 XPath 的提出的初衷是将其作为一个通用的、介于XPointer与XSLT间的语法模型。但是 XPath 很快的被开发者采用来当作小型查询语言。 XPath设计的核心思想:迅速定位(不是通过循环遍历)到你所需要的元素(或者...

    python爬虫mac版本猪精原创

    - xpath语法 - xpath helper插件:帮助我们从`elements`中定位数据 - 1. 选择节点(标签) - `/html/head/meta` :能够选中html下的head下的所有的meta标签 - 2. `//` :能够从任意节点开始选择 - `//li` :当前...

    dom4j,jaxen.rar

    解析复杂的xml,引入jaxen包,dom解析支持xpath,是复杂的xml解析更简单,可以通过xpath语法直接找到对应的节点,数据

Global site tag (gtag.js) - Google Analytics