我是靠谱客的博主 拉长抽屉,最近开发中收集的这篇文章主要介绍xpath 语法(节点)XPath Nodes,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

(转自: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 Nodes的全部内容,希望文章能够帮你解决xpath 语法(节点)XPath Nodes所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(46)

评论列表共有 0 条评论

立即
投稿
返回
顶部