Path Expressions

XPATH Path ExpressionsXPATH path expressions are used to refer to specific nodes or values in an XML document.

The XPATH expression syntax appears much like a file system path to address the hierarchical nature of an XML document.

The following are common path expressions to use:

Path ExpressionDescription
nodenameSelects a node and all of its children
/Selects the document root
//Selects a node and all of its children; regardless of where it is located in the XML document hierarchy.

The use of this path expression can kill performance in large documents – the parser looks at every node. Give the parser some hints by narrowing the search; try to use specific paths or wildcards.

.Selects the current node
..Selects the parent node in relation to the current node.
@Selects an attribute

Combining path expressions with wildcards and  XPATH functions offers a robust method to reference nodes/values in an XML document.

The following examples shows how to use the path expressions in a meaningful way:

Posted in XPATH and tagged .

Leave a Reply