XPath

 
 
XPath is a syntax for defining the parts of an XML document.

More information about XPath can be found at: http://www.w3.org/TR/xpath

rss feed

Quick guides






XPath terminology.




XML example:

<?xml version="1.0" encoding="ISO-8859-1"?>

<description>Employees working for Mobilefish.com</description>
<employees>
   <employee id="1000">
      <firstName>Joe</firstName>
      <lastName>Smith</lastName>
      <securityLevel>1</securitylevel>
   </employee>
   <employee id="2000">
      <firstName>Jack</firstName>
      <lastName>Brown</lastName>
      <securityLevel>1</securitylevel>
   </employee>
</employees>


Node name In XML Path expression
ancestors The node its parents.

The firstName ancestors are employee and employees.

 
atomic values Does not have childeren or parents and does not contain any other value.

Example: the values 1000 or Joe are atomic values.
 
attribute Values assigned to a node.

Example: id="1000" is an attribute node.
@
child firstName, lastName and securityLevel are children of employee  
descendants The node its children.

The descendants of employees are employee, firstName, lastName and securityLevel.

 
element node <firstName>Joe</firstName>  
expression Expressions are put inside the brackets.

Example: employee[lastName='Smith']

This syntax is to find all employee nodes, whose lastName element has the value Smith.
[]
node A node can be an element, attribute, namespace, text, comment, processing instruction or document node.  
parent employee is the parent of firstName, lastName and securityLevel ..
self The current node in the context.

.
siblings nodes that have the same parent.

firstName, lastName and securityLevel are all siblings

 
Document node or root node.

The node in context.
Example: /employees

Selects the employees element, starting at the root of the document.

Example: employee/firstName

Select all firstName elements that are children of employee.
/
All elements where they are in the document. Example: //firstName

Select all firstName elements no matter where they are in the document.

Example: employees//firstName

Select all fistName elements that are descendant of the employees element, no matter where they exist under the employees element.
//