XPath
- XPath is used to navigate through elements and attributes in an XML document.
- XPath is a language for finding information in an XML document.
- In XPath, there are seven kinds of nodes:
- element
- attribute
- text
- namespace
- processing-instruction
- comment
- document
- Look at the following XML document:
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book>
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
<bookstore>
<book>
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
<bookstore> (root element node)
<author>J K. Rowling</author> (element node)
lang="en" (attribute node)
<author>J K. Rowling</author> (element node)
lang="en" (attribute node)
- Atomic values/Items/Node- Atomic values are nodes with no children or parent. e.g.
J K. Rowling
"en"
- Relationship of Nodes
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
- Parent- Each element and attribute has one parent. e.g. book is parent is of title/author/year/price
- Children- Element nodes may have zero, one or more children. e.g. title/author/year/price are children of book
- Siblings- Nodes that have same parent e.g. title/author/year/price
- Ancestors- Node's parent, parent's parent e.g. book is ancestor of title/author/year/price
- Descendants- Node's children, children's children e.g. title/author/year/price are descendants of book
- Basic XPath Syntax- Refer following article -
No comments:
Post a Comment