XQuery Terminology

在 XQuery 中,有七种节点:元素、属性、文本、命名空间、处理指令、注释、以及文档节点(或称为根节点)。

XQuery Terminology

节点

在 XQuery 中,有七种节点:元素、属性、文本、命名空间、处理指令、注释、以及文档(根)节点。XML 文档是被作为节点树来对待的。树的根被称为文档节点或者根节点。

请看下面的 XML 文档:

<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book>
  <title lang="en">Harry Potter</title>
  <author>J K. Rowling</author> 
  <year>2005</year>
  <price>29.99</price>
</book>
</bookstore>

上面的 XML 文档中的节点例子:

<bookstore>  (文档节点)
<author>J K. Rowling</author>  (元素节点)
lang="en"  (属性节点)

基本值(或称原子值,Atomic value)

基本值是无父或无子的节点。

基本值的例子:

J K. Rowling
"en"

Item

Items are basic values or nodes.

Node Relationships

Parent

Each element and attribute has a parent.

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

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

Children

A node element may have zero, one, or more children.

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

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

Sibling

Nodes with the same parent.

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

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

Ancestor

Parent, parent's parent, and so on.

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

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

Descendant

Child, child's child, and so on.

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

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