Terminologi XQuery

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

Terminologi XQuery

节点

在 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"

Projek

Projek adalah nilai dasar atau noda.

Hubungan Noda

Bapak (Parent)

Setiap elemen dan atribut memiliki seorang bapak.

Dalam contoh di bawah ini, elemen book adalah bapak dari elemen-elemen title, author, year serta price:

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

Anak (Children)

Elemen node dapat memiliki nol, satu, atau beberapa anak.

Dalam contoh di bawah ini, elemen-elemen title, author, year serta price adalah anak dari elemen book:

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

Saudara (Sibling)

Noda yang memiliki bapak yang sama.

Dalam contoh di bawah ini, elemen-elemen title, author, year serta price adalah saudara:

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

Orangtua (Ancestor)

Orang tua, orang tua bapak, dan seterusnya.

Dalam contoh di bawah ini, bapak dari elemen title adalah elemen book serta bookstore:

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

Anak (Descendant)

Anak, anak-anak, dan seterusnya.

Dalam contoh di bawah ini, anak dari bookstore adalah elemen-elemen book, title, author, year serta price:

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