Encyclopedia > XPath

  Article Content

XPath

XPath is a terse (non-XML) syntax for addressing portions of an XML document.

Originally motivated by a desire to provide a common syntax and behavior model between XPointer and XSL, XPath has rapidly been adopted by developers as a small query language.

Notation

The notation is compact, suitable for expressing within XML attributes. A typical XPath expression is a _Location Path_ consisting of a string of element or attribute qualifiers separated by forward slashes ("/"), similar in appearance to a file system path. XPath also allows built-in functions, filters, bound variable access, and axis specifiers.

Location Paths are divided into Steps, each of which has three components:

An Axis Specifier indicates the kind of information which will be selected. For instance, _child::_ is the unabbreviated axis specifier for element children. For many XPath expressions, the axis specifier is omitted allowing it to default to _child::_. A common abbreviated axis specifier is a commercial "at" sign ("@"), which represents attributes.

A Node Test limits the specific elements or attributes which will be addressed. A common form of node test is a _name test_ which is the name of an element or an attribute.

Predicates are used to filter out, or exclude, certain nodes on the basis of more complex expressions. Predicates are introduced using a square-bracket ("[", "]") syntax.

Examples

An exhaustive set of examples is beyond the scope of this article. Some typical XPath expressions which might be used in an XSL context are:

The Root element
/*

All elements everywhere (implementations of this expression can be very slow)
//*

All Top Level Elements (children of Root)
/*/*

The fifth child element under an element named "FOOB"
FOOB[5]

The element FOOB whose BAZ attribute is "untrue"
FOOB[ @BAZ = "untrue" ]

See also:



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
Shinnecock Hills, New York

... are Hispanic or Latino of any race. There are 502 households out of which 24.1% have children under the age of 18 living with them, 52.8% are married couples living ...

 
 
 
This page was created in 36.1 ms