XPath Basic

什么是XPath?

  • XPath is a syntax(语法) for defining parts of an XML document
  • XPath uses path expressions(路径表达式) to navigate(导航,定位) in XML documents
  • XPath contains a library of standard functions (包含一些标准函数库)
  • XPath is a major element in XSLT (XSLT的主要构成部份)
  • XPath is a W3C Standard (W3C的一个标准)

 

XPath Path Expressions(路径表达式)

XPath uses path expressions to select nodes(节点) or node-sets(节点集) in an XML document. These path expressions look very much like the expressions you see when you work with a traditional computer file system.

XPath通过路径表达式来选择XML文档中的节点或节点集,这些表达式很像那些传统的电脑文件系统的表达式.

 

XPath Standard Functions(标准函数)

XPath includes over 100 built-in functions. There are functions for string values, numeric values, date and time comparison, node and QName manipulation, sequence manipulation, Boolean values, and more.

XPath 包含100多个内建函数,这些函数可以返回字符串值,数值,日期和时间的比较值,节点和QName操作,因果关系操作,布尔值,还有其它等.

 

XPath is Used in XSLT

XPath is a major element in the XSLT standard. Without XPath knowledge you will not be able to create XSLT documents.

没有XPath知识你将不能创建有效的,灵活的XSLT文档

XQuery and XPointer are both built on XPath expressions. XQuery 1.0 and XPath 2.0 share the same data model and support the same functions and operators.

XQuery 1.0 和 XPath 2.0有共同的数据模式,支持相同的函数和操作

 

XPath is a W3C Standard

XPath became a W3C Recommendation 16. November 1999.

XPath was designed to be used by XSLT, XPointer and other XML parsing software.

 

XPath Terminology术语

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

在 XPath中,共有七种节点:元素,属性,文本,命名空间,处理指令,注释和文档根节点.

看下面这个例子:

<?xml version="1.0" encoding="iso-8859-1"?>
<bookstore> <!--document node-->
  <book> <!--element node-->
    <title lang="en">Harry Potter</title> <!--lang="en"  attribute node)-->
    <author>J K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
  </book>
</bookstore>

 

Atomic values(原子值)

Atomic values are nodes with no children or parent.

原子值是没有子节点和父节点的节点,如上例中的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元素是title, author, year, 和 price的父节点:

<book>
  <title>Harry Potter</title>
  <author>J K. Rowling</author>
  <year>2005</year>
  <price>29.99</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>
  <title>Harry Potter</title>
  <author>J K. Rowling</author>
  <year>2005</year>
  <price>29.99</price>
</book>

Siblings同胞,同科,平行

Nodes that have the same parent.具有相同父节点的节点

In the following example; the title, author, year, and price elements are all siblings:下例中,title, author, year, 和 price 元素都是同科

<book>
  <title>Harry Potter</title>
  <author>J K. Rowling</author>
  <year>2005</year>
  <price>29.99</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:

下例中,title元素的根是book和bookstore元素

<bookstore>
  <book>
    <title>Harry Potter</title>
    <author>J K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
  </book>
</bookstore>

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元素的胄是book,title,author,year和price元素

<bookstore>
  <book>
    <title>Harry Potter</title>
    <author>J K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
  </book>
</bookstore>
posted @ 2008-08-31 00:11  Scott Xu(南方小鬼)  阅读(259)  评论(0编辑  收藏  举报
乘客