Node XPath

Dalam XPath, ada tujuh jenis node: elemen, atribut, teks, namespace, perintah pemrosesan, komentar serta node dokumen (atau disebut root node).

Terminologi XPath

Node

Dalam XPath, ada tujuh jenis node: elemen, atribut, teks, namespace, perintah pemrosesan, komentar serta node dokumen (atau disebut root node). Dokumen XML dianggap sebagai pohon node. Akar pohon disebut node dokumen atau root node.

Lihat dokumen XML di bawah ini:

<?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>

Contoh node di dalam dokumen XML di atas:

<bookstore> (node dokumen)
<author>J K. Rowling</author> (node elemen)
lang="en" (node atribut) 

Nilai dasar (atau disebut nilai atom, Atomic value)

Nilai dasar adalah node tanpa ayah atau anak.

Contoh nilai dasar:

J K. Rowling
"en"

Proyek (Item)

Proyek adalah nilai dasar atau node.

Hubungan node

Ayah (Parent)

Setiap elemen dan atribut memiliki ayah.

Dalam contoh di bawah ini, elemen book adalah ayah dari 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)

Node elemen dapat memiliki nol, satu, atau beberapa anak.

Dalam contoh di bawah ini, 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)

Node yang memiliki ayah yang sama

Dalam contoh di bawah ini, 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>

Nenek moyang (Ancestor)

Ayah, ayah ayah, dan seterusnya dari suatu node.

Dalam contoh di bawah ini, elemen title adalah nenek moyang dari elemen book dan bookstore:

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

Klanakang (Descendant)

Anak dari suatu node, anak-anak anak, dan seterusnya.

Dalam contoh di bawah ini, klanakankan 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>