What is XPath?

Sometime, the data in an XML document needs to be searched before it can be formatted and rendered using a style sheet. Here XPath comes in to picture.

XPath is used to search and reterive information from an XML file. It treats an XML document as a tree of interrelated branches and nodes of any type, such an element, attribute, comment.

In below picture,you will see CompanyData, DepartmentName are element nodes and CID is attribute nodes. Software represent text nodes.
XPath provides a set of expressions and functions that can be used to match nodes in an XML document. A set of nodes or node set is retrive when you match nodes with a specific pattern.

XPath Expressions: Using XPath we can create XPath expressions to identify the nodes in xml based on their name and values. These Expressions can be used with XSLT patterns to match and retrieve nodes.

Node Selection

The node is selected by following a path or steps. The most useful path expressions are listed below:

Expression Description

nodename Selects all child nodes of the named node
/ Selects from the root node
// Selects nodes in the document from the current node that match
the selection no matter where they are
. Selects the current node
.. Selects the parent of the current node
@ Selects attributes

Describing XPath Functions
The Various categories of functions in XPath are

string Functions: It is used to perform string operations such as finding the length of a string or converting a string from uppercase to lower case. Even we can use these functions to manipulate the text content of an XML element or attribute.

node-set Functions: Used to manipulate node-set or to return information about them.

Boolean Functions: Used to return true or false.

numeric Functions: XPath provides numeric functions for various purpose such as adding numbers, finding the nearest integer value and so many.


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: