XPATH-Relationships of Nodes

Estudies4you
Relationships of Nodes-XPATH
Relationships of Nodes
There are five types of relationships amongst nodes:
  • Parent
  • Child
  • Sibling
  • Ancestor
  • Descendant
Parent
  • Each element and attribute has one parent.
  • Consider the following example; the book element is the parent of the title, author, year, and price:

<book>
<title lang="en">Web Technologies</title>
<author>Kogent</author>
<year>2010</year>
<price>300.00</price>
</book>

Child
  • Element nodes may have zero, one or more children
  • Consider the following example; the title, author, year, and price elements are all children of the book element:
<book>
<title lang="en">Web Technologies</title>
<author>Kogent</author> <year>2010</year>
<price>300.00</price>
</book>

Sibling
  • Nodes that have the same parent
  • Consider the following example; the title, author, year, and price elements are all siblings:

<book>
<title lang="en">Web Technologies</title>
<author>Kogent</author>
<year>2010</year>
<price>300.00</price>
</book>

Ancestor
  • A node's parent, parent's parent, etc
  • Considerthefdlowing example; the ancestors of the title element are the book element and the bookstore element:
<bookstore>
<book>
<title lang="en">Web Technologies</title>
<author>Kogent</author>
<year>2010</year>
 <price>300.00</price>
</book>
</bookstore>

Descendant
  • A node's children, children's children, etc
  • Consider the following example; descendants of the bookstore element are the book, title, author, year, and price elements:
<bookstore>
<book>
<title lang="en">Web Technologies</title>
<author>Kogent</author>
<year>2010</year>
<price>300.00</price>
</book>
</bookstore>


To Top