XPath
XPath is an expression language for addressing parts of an XML
document. You can think of XPath expressions as sort of like regular
expressions for XML. They let you pull out parts of an XML document based
on patterns. In the case of XPath, the patterns are more concerned with
structural information than with character content and the values returned
may be either simple text or “live” DOM nodes. With XPath, we can query an
XML document for all of the elements with a certain name or in a certain
parent-child relationship. We can also apply fairly sophisticated tests or
predicates to the nodes, which allows us to construct
complex queries such as this one: give me all of the Animals with a Weight greater than the number 400 and a
Temperament of irritable whose animalClass attribute is mammal.
The full XPath specification has many features and includes both a compact and more verbose syntax. We won’t try to cover it all here, but the basics are easy and it’s important to know them because XPath expressions are at the core of XSL transformations and other APIs that refer to parts of XML documents. The full specification does not make great bedtime reading, but can be found at http://www.w3.org/TR/xpath.
Nodes
An XPath expression addresses a Node in an XML document tree. The node may be
an element (possibly with children) like <animal>...</animal> or it may be
a lower-level document node representing an attribute (e.g., animalClass="mammal"), a CDATA block, or even a comment. All ...