Navigation in XQuery

This chapter explores how XQuery provides a litany of navigation expressions. It is designed to be a language in which queries are concise and easily understood. It is also flexible enough to query a broad spectrum of XML information sources, including both databases and documents.

This chapter is from the book

This chapter is from the book

3.1 Introduction

Once you've constructed or loaded XML in a query, you need a way to navigate over that hierarchical data. In many ways, construction and navigation are the primary operations in any XML query language. XQuery provides a litany of navigation expressions, and this chapter explores them all. Readers who are already
familiar with XPath 1.0 may safely skim this chapter. XQuery has some differences from XPath 1.0, but they are minor.

Navigation involves starting from one part of an XML data model and moving to another part of the data model. Navigation can involve local steps, for example, moving from a node
to one of its neighbors, or global steps, such as moving from a node to a completely different part of the data model, or
even another document.

If you're familiar with relational databases, it may help to reflect that navigating is to XML nodes what cursoring is to relational rowsets. Like using regular expressions to parse strings, using navigation in a query
is generally more efficient in space and time than manually traversing an XML structure.