A key requirement for dissecting
nearly any XPath expression is an understanding of Location
Paths, which select one or more nodes based on their
location or other properties. A Location Path consists of a number of
individual Location Steps, each separated by a
individual step builds upon the previous steps to traverse the
document, and can be a test against the name of a node, or one of the
following special tests:
Matches any node whatsoever.
Matches any text node.
Matches any comment node.
Matches any processing instruction node, and may have a parameter to match against a specific processing instruction.
Another special test is
*, which will match any
element node (or attribute node within the
attribute axis, or namespace node within the
namespace axis.) Similarly, another special test
match any node identified with the namespace mapped to
Figure 3-2 illustrates how a path is traversed in steps, from left to right.
Figure 3-2. Location paths and steps
Extra care is needed when traversing a document that contains XML namespaces, especially with defaulted namespaces. Any namespace prefixes in scope can be used in Location Steps; however, default namespaces in scope do not apply to the XPath expression.
For example, to address the
item elements in this example: ...