O'Reilly logo

XForms Essentials by Micah Dubinko

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Location Paths

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 slash (/). Each 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:

node( )

Matches any node whatsoever.

text( )

Matches any text node.

comment( )

Matches any comment node.

processing-instruction( )

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 prefix:* will match any node identified with the namespace mapped to prefix.

Figure 3-2 illustrates how a path is traversed in steps, from left to right.

Location paths and steps

Figure 3-2. Location paths and steps

Warning

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: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required