XPath is used to navigate through elements and attributes in an XML document, so to utilize it, you would need prior knowledge of XML. XPath is a major element in W3C’s XSLT standard – and XQuery and XPointer are both built on XPath expressions. XPath uses path expressions to select nodes or node-sets in an XML document. These path expressions look very much like the expressions you see when you work with a traditional computer file system. XPath has a wide range of selections. It includes over 100 built-in functions. There are functions for string values, numeric values, date and time comparison, node and QName manipulation, sequence manipulation, Boolean values, and more.
Most important aspect of XPath operations is a node. In XPath, there are seven kinds of nodes: element, attribute, text, namespace, processing-instruction, comment, and document nodes. Consider a short example:
1 2 3 4 5 6 7 8 9 |
<em><?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></em> |
Example of node in the XML document above is:
1 2 3 |
<em><bookstore> (root element node) <author> J K. Rowling</author> (element node) lang="en" (attribute node)</em> |
Like any programming language, the parent-child relationship exists between nodes in XPath as well. In the above given piece of code, <book> is the parent node while <title>, <author>, <year>, <price> etc. are all examples of child node. Nodes that have the same parents are known as sibling nodes. Certain things like use of functions and predicates are similar in XPath and XQuery (both these aspects have been explained in an article about XQuery). Overall, XPath, along with XQuery has wide range of features and functions that can be utilized in web programming and hence, is increasingly used by web programmers all around the world.
, <author>, <year>, <price> etc. are all examples of child node. Nodes that have the same parents are known as sibling nodes. Certain things like use of functions and predicates are similar in XPath and XQuery (both these aspects have been explained in an article about XQuery). Overall, XPath, along with XQuery has wide range of features and functions that can be utilized in web programming and hence, is increasingly used by web programmers all around the world. </p>