Home > Articles > Web Services > XML

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

3.3 Navigation Functions

All of the navigation we've considered so far amounts to local steps: from the current context, navigate to some nearby nodes. However, XQuery also defines functions that can navigate more globally to other parts of a document or different documents. These functions are summarized in Table 3.2, and fully documented in Appendix C.

Of these, the doc() function is the only one you are likely to commonly use. It takes a single string argument, which is treated as the URI location of an XML document. It then loads that document and returns the corresponding XQuery Data Model instance. Certain aspects of this process, such as security permissions and schema validation, vary from one implementation to the next.

Table 3.2. Navigation functions

Function

Meaning

XPath 1.0?

collection()

A named sequence

No

doc()

Navigate to the root of the named XML document

No

id()

Navigate to the (unique) element with this ID

Yes

idref()

Navigate to the elements that refer to this one

No

root()

Navigate to the root of the current document

No

If the document cannot be found or is not well-formed, some implementations will raise an error, although they are also allowed to just return the empty sequence. (This is mainly to allow certain XQuery optimizations; for example, doc("x")[false()] could be optimized into the empty sequence without attempting to load the document.)

The other functions are much less commonly used, so we defer their description to Appendix C.

  • + Share This
  • 🔖 Save To Your Account