|
The XPath a language is a W3C standard for for selecting nodes from an XML document. In addition, XPath may be used to compute values (strings, numbers, or boolean values) from the content of an XML document. Put simply It is to XML what SQL is to relational databases.
The XPath language is based on a tree representation of the XML document, and provides the ability to navigate around the tree, selecting nodes by a variety of criteria.
Originally motivated by a desire to provide a common syntax and behavior model between XPointer and XSLT, subsets of the XPath query language are used in other W3C specifications such as XML Schema and XForms.
XPath Versions
XPath 1.0
XPath Version 1.0 became a recommendation in Nov 1999. The standard allows for basic navigation of the XML tree, and the ability to control the selection of nodes within it.
XPath 2.0
XPath 2.0 became a recomendation in Jan 2007. This version brings together a number of technologies, XPATH, XSLT & XQuery. XPATH 2.0 is a subset of the XQuery 1.0 standard and , it is a subset of XSLT 2.0.
In addition to the functionality offered in XPath 1.0, XPath 2.0 allows for strongly typed data types, and conditional expressions and for loops.
XPath 2.0 is mostly backwardly compatabile with XPath 1.0, but may produce different results due to changes in the way types are delt with ie in 2.0 "4.0" = "4" as it could evaluate them as decimal values, but in 1.0 it would always treat them as strings.
Example
<?xml version="1.0" encoding="utf-8"?>
<Catalog>
<Album artist="The Last Shadow Puppets" title="The Age Of The Understatement">
<Track rating="4" length="P3M7S">The Age Of The Understatement</Track>
<Track rating="3" length="P2M18S">Standing Next To Me</Track>
<Track rating="5" length="P2M26S">Calm Like You</Track>
<Track rating="3" length="P3M38S">Separate and Ever Deadly</Track>
<Track rating="2" length="P2M37S">The Chamber</Track>
<Track rating="3" length="P2M44S">Only The Truth</Track>
</Album>
<Album artist="Kings Of Leon" title="Because Of The Times">
<Track rating="4" length="P7M10S">Knocked Up</Track>
<Track rating="2" length="P2M57S">Charmer</Track>
<Track rating="3" length="P3M21S">On Call</Track>
<Track rating="4" length="P3M09S">McFearless</Track>
<Track rating="1" length="P3M59S">Black Thumbnail</Track>
</Album>
</Catalog>
Using the XPath Expression
/Catalog/Album/Track[@rating>2]
Will Select the highlighted nodes

XPath Tools
|