Noda XPath
Dalam XPath, ada tujuh jenis node: elemen, atribut, teks, namespace, perintah pemrosesan, komentar serta node dokumen (atau disebut root node).
Termin 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 Nodi
Bapak (Parent)
Setiap elemen dan atribut memiliki bapak.
Dalam contoh di bawah, elemen book adalah bapak 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)
Nodi elemen dapat memiliki nol, satu, atau beberapa anak.
Dalam contoh di bawah, elemen-elemen title, author, year serta price adalah anak book:
<book> <title>Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book>
Saudara (Sibling)
Nodi yang memiliki ayah yang sama
Dalam contoh di bawah, 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>
Bapak (Ancestor)
Ayah, ayah-ayah, dan seterusnya.
Dalam contoh di bawah, bapak title adalah elemen book dan 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, anak-anak 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>