ตัวเลือก XPath

ใน XPath มีชนิดของโครงสร้างเจ็ดราย: element, attribute, text, namespace, processing instruction, comment และ document node (หรือเรียกว่า root node)

วลีของ XPath

โครงสร้าง (Node)

ใน XPath มีชนิดของโครงสร้างเจ็ดราย: element, attribute, text, namespace, processing instruction, comment และ document (root) node. 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> (document node)
<author>J K. Rowling</author> (element node)
lang="en" (node attribute) 

ค่าพื้นฐาน (หรือเรียกว่าค่าอะตอม Atomic value)

ค่าพื้นฐานไม่มีพ่อหรือลูก

ตัวอย่างของค่าพื้นฐาน:

J K. Rowling
"en"

โครงสร้าง (Item)

โครงสร้าง (Item) คือค่าพื้นฐานหรือโครงสร้าง

ความสัมพันธ์ของโครงสร้าง

พ่อ (Parent)

แต่ละ element และ attribute มีพ่อ

ในตัวอย่างด้านล่างนี้ element book มีพ่อของ element title, author, year และ element price:

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

ลูก (Children)

element ของโครงสร้างสามารถมีลูกโครงสร้าง 0 อัน, 1 อัน หรือหลายอัน

ในตัวอย่างด้านล่างนี้ element title, author, year และ element price ต่างกันเป็นลูกของ element book:

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

ครรภ์ (Sibling)

ตัวเลขที่มีพ่อเดียวกัน

ในตัวอย่างด้านล่างนี้ element title, author, year และ element price ต่างกันเป็นครรภ์:

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

พ่อทั้งหมด (Ancestor)

พ่อของโครงสร้างหรือพ่อของพ่อของโครงสร้าง และอื่นๆ

ในตัวอย่างด้านล่างนี้ element title มีพ่อทั้งหมดเช่น element book และ element bookstore:

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

หลักของที่เป็นเด็ก (Descendant)

ลูกของตัวเลของโครงสร้างหรือลูกของลูกของโครงสร้าง และอื่นๆ

ในตัวอย่างด้านล่างนี้ bookstore มีหลักของที่เป็นเด็กทั้งหมดเช่น book, title, author, year และ element price:

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