Processing Queries

A simple example of a processing model for XQuery is shown in Figure 2-1. This section describes the various components of this model.

A Basic XQuery processor

Figure 2-1. A Basic XQuery processor

XML Input Documents

Throughout this book, the term input document is used to refer to the XML data that is being queried. The data that is being queried can, in fact, take a number of different forms, for example:

  • Text files that are XML documents

  • Fragments of XML documents that are retrieved from the Web using a URI

  • A collection of XML documents that are associated with a particular URI

  • Data stored in native XML databases

  • Data stored in relational databases that have an XML frontend

  • In-memory XML documents

Some queries use a hardcoded link to the location of the input document(s), using the doc or collection function in the query. Other queries operate on a set of input data that is set by the processor at the time the query is evaluated.

Whether it is physically stored as an XML document or not, an input document must conform to other constraints on XML documents. For example, an element may not have two attributes with the same name, and element and attribute names may not contain special characters other than dashes, underscores, and periods.

The Query

An XQuery query could be contained in a text file, embedded in program code or in a query library, generated dynamically by program code, or input by ...

Get XQuery now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.