XPath Nodes

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

XPath 术语

节点(Node)

在 XPath 中,有七种类型的节点:元素、属性、文本、命名空间、处理指令、注释以及文档(根)节点。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"

Proyekto (Item)

Ang mga proyekto ay maaaring maging pangunahing halaga o node.

Relasyon ng Node

Magulang (Parent)

Bawat elemento at attribute ay may magulang.

Sa mga sumusunod na halimbawa, ang elemento na book ay ang magulang ng mga elemento na title, author, year at price:

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

Anak (Children)

Ang elemento ng isang bagay ay maaaring may wala, isa o maraming anak.

Sa mga sumusunod na halimbawa, ang mga elemento na title, author, year at price ay mga anak ng elemento na book:

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

Magkakapatid (Sibling)

Mga bagay na may parehong magulang.

Sa mga sumusunod na halimbawa, ang mga elemento na title, author, year at price ay mga magkakapatid:

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

Magulang (Ancestor)

Magulang ng isang bagay, magulang ng magulang, at iba pa.

Sa mga sumusunod na halimbawa, ang mga magulang ng elemento na title ay ang mga elemento na book at bookstore:

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

Anak (Descendant)

Anak ng isang bagay, anak ng anak, at iba pa.

Sa mga sumusunod na halimbawa, ang mga anak ng bookstore ay ang mga elemento na book, title, author, year at price:

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