Chapter 4. Navigating Input Documents Using Paths
Path expressions are used to navigate input documents to select elements and attributes of interest. This chapter explains how to use path expressions to select elements and attributes from an input document and apply predicates to filter those results. It also covers the different methods of accessing input documents.
Path Expressions
A path expression is made up of one or more steps that are separated by a slash (/) or double slashes (//). For example, the path:
doc("catalog.xml")/catalog/productselects all the product children of the catalog element in the catalog.xml document. Table 4-1 shows some other simple path expressions.
Table 4-1. Simple path expressions
|
Example |
Explanation |
|---|---|
|
|
The |
|
|
All |
|
|
All |
|
|
All child elements of the |
|
|
All |
Path expressions return nodes in document order. This means that the examples in Table 4-1 return the product elements in the same order that they appear in the catalog.xml document. More information on document order and on sorting results differently can be found in Chapter 7.
Path Expressions and Context
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access