XQuery: An XML Query Language Resources & References
XQuery 1.0: An XML Query Language
XML is a versatile markup language, capable of labeling the information content of diverse data sources including structured and semi-structured documents, relational databases, and object repositories. A query language that uses the structure of XML intelligently can express queries across all these kinds of data, whether physically stored in XML or viewed as XML via middleware. This specification describes a query language called XQuery, which is designed to be broadly applicable across many types of XML data sources.
The XML Query 1.0 Requirements states that The XML Query Language MAY have more than one syntax binding. One query language syntax MUST be convenient for humans to read and write. One query language syntax MUST be expressed in XML in a way that reflects the underlying structure of the query.
XQueryX is an XML representation of an XQuery. It was created by mapping the productions of the XQuery grammar into XML productions. The result is not particularly convenient for humans to read and write, but it is easy for programs to parse, and because XQueryX is represented in XML, standard XML tools can be used to create, interpret, or modify queries.
Note: Because the two syntaxes are merely different grammars that express the same query semantics, they share all aspects of an XQuery processing system except for the component that recognizes and translates the source representation of a query (that is, the parser). The aspects that are shared include both the static context and the dynamic context that are defined in XQuery 1.0: An XML Query Language.
There are several environments in which XQueryX may be useful:
- Parser Reuse. In heterogeneous environments, a variety of systems may be used to execute a query. One parser can generate XQueryX for all of these systems.
- Queries on Queries. Because XQueryX is represented in XML, queries can be queried and can be transformed into new queries. For instance, a query can be performed against a set of XQueryX queries to determine which queries use FLWOR expressions to range over a set of invoices.
- Generating Queries. In some XML-oriented programming environments, it may be more convenient to build a query in its XQueryX representation than in the corresponding XQuery representation, since ordinary XML tools can be used.
- Embedding Queries in XML. XQueryX can be embedded directly in an XML document.
The most recent versions of the XQueryX XML Schema and the XQueryX XSLT stylesheet are available at http://www.w3.org/2005/XQueryX/xqueryx.xsd and http://www.w3.org/2005/XQueryX/xqueryx.xsl, respectively.
This document defines the W3C XQuery 1.0 and XPath 2.0 Data Model (XDM), which is the data model of XPath 2.0, XSLT 2.0, and XQuery, and any other specifications that reference it. This data model is based on the XPath 1.0 data model and earlier work on an XML Query Data Model. This document is the result of joint work by the XSL Working Group and the XML Query Working Group.
This document defines constructor functions, operators and functions on the datatypes defined in XML Schema Part 2: Datatypes Second Edition and the datatypes defined in XQuery 1.0 and XPath 2.0 Data Model. It also discusses functions and operators on nodes and node sequences as defined in the XQuery 1.0 and XPath 2.0 Data Model. These functions and operators are defined for use in XML Path Language (XPath) 2.0, XQuery 1.0: An XML Query Language and XSL Transformations (XSLT) Version 2.0 and other related XML standards. The signatures and summaries of functions defined in this document are available at: http://www.w3.org/2005/xpath-functions.
This document defines the syntax and semantics of an extension to XQuery 1.0 called the XQuery Update Facility 1.0. This language extension is designed to meet the requirements for updating instances of the XQuery/XPath Data Model (XDM), as defined in XQuery Update Facility Requirements.
The XQuery Update Facility 1.0 provides facilities to perform any or all of the following operations on an XDM instance:
- Insertion of a node.
- Deletion of a node.
- Modification of a node by changing some of its properties while preserving its node identity.
- Creation of a modified copy of a node with a new node identity.
Additionally, this document defines an XML syntax for the XQuery Update Facility 1.0. The most recent versions of the two XQueryX XML Schemas and the XQueryX XSLT stylesheet for the XQuery Update Facility 1.0 are available at http://www.w3.org/2007/xquery-update-10/xquery-update-10-xqueryx.xsd, http://www.w3.org/2007/xquery-update-10/xquery-update-10-xqueryx-redef.xsd, and http://www.w3.org/2007/xquery-update-10/xquery-update-10-xqueryx.xsl, respectively.
This document defines the formal semantics of XQuery 1.0 and XPath 2.0. The present document is part of a set of documents that together define the XQuery 1.0 and XPath 2.0 languages:
- XQuery 1.0: An XML Query Language introduces the XQuery 1.0 language, defines its capabilities from a user-centric view, and defines the language syntax.
- XML Path Language (XPath) 2.0 introduces the XPath 2.0 language, defines its capabilities from a user-centric view, and defines the language syntax.
- Functions and Operators lists the functions and operators defined for the XPath/XQuery language and specifies the required types of their parameters and return value.
- Data Model formally specifies the data model used by XPath/XQuery to represent the content of XML documents. The XPath/XQuery language is formally defined by operations on this data model.
- Data Model Serialization specifies how XPath/XQuery data model values are serialized into XML.
The scope and goals for the XPath/XQuery language are discussed in the charter of the W3C XSL/XML Query Working Group and in the XPath/XQuery requirements XML Query 1.0 Requirements.
This document defines the semantics of XPath/XQuery by giving a precise formal meaning to each of the expressions of the XPath/XQuery specification in terms of the XPath/XQuery data model. This document assumes that the reader is already familiar with the XPath/XQuery language. This document defines the formal semantics for XPath 2.0 only when the XPath 1.0 backward compatibility rules are not in effect.
Two important design aspects of XPath/XQuery are that it is functional and that it is typed. These two aspects play an important role in the XPath/XQuery Formal Semantics.
XPath/XQuery is a functional language. XPath/XQuery is built from expressions, rather than statements. Every construct in the language (except for the XQuery query prolog) is an expression and expressions can be composed arbitrarily. The result of one expression can be used as the input to any other expression, as long as the type of the result of the former expression is compatible with the input type of the latter expression with which it is composed. Another characteristic of a functional language is that variables are always passed by value, and a variable's value cannot be modified through side effects.
XPath/XQuery is a typed language. Types can be imported from one or more XML Schemas that describe the input documents and the output document, and the XPath/XQuery language can then perform operations based on these types. In addition, XPath/XQuery supports static type analysis. Static type analysis infers the output type of an expression based on the type of its input expressions. In addition to inferring the type of an expression for the user, static typing allows early detection of type errors, and can be used as the basis for certain classes of optimization. The XPath/XQuery type system captures most of the features of Schema Part 1, including global and local element and attribute declarations, complex and simple type definitions, named and anonymous types, derivation by restriction, extension, list and union, substitution groups, and wildcard types. It does not model uniqueness constraints and facet constraints on simple types.
This document is organized as follows. 2 Preliminaries introduces the notations used to define the XPath/XQuery Formal Semantics. These include the formal notations for values in the XPath/XQuery data model and for types in XML Schema. The next three sections: 3 Basics, 4 Expressions, and 5 Modules and Prologs have the same structure as the corresponding sections in the XQuery 1.0: An XML Query Language and XML Path Language (XPath) 2.0 documents. This allows the reader to quickly find the formal definition of a particular language construct. 3 Basics defines the semantics for basic XPath/XQuery concepts, and 4 Expressions defines the dynamic and static semantics of each XPath/XQuery expression. 5 Modules and Prologs defines the semantics of the XPath/XQuery prolog. 7 Additional Semantics of Functions defines the static semantics of several functions in Functions and Operators and gives the dynamic and static semantics of several supporting functions used in this document. The remaining sections, 8 Auxiliary Judgments and D Importing Schemas, contain material that supports the formal semantics of XPath/XQuery. 8 Auxiliary Judgments defines formal judgments that relate data model values to types, that relate types to types, and that support the formal definition of validation. These judgments are used in the definition of expressions in 4 Expressions. Lastly, D Importing Schemas, specifies how XML Schema documents are imported into the XPath/XQuery type system and relates XML Schema types to the XPath/XQuery type system.
This specification defines an extension to XQuery 1.0 and XQuery Update Facility. Expressions can be evaluated in a specific order, with later expressions seeing the effects of the expressions that came before them. This specification introduces the concept of a block with local variable declarations, as well as several new kinds of expressions, including assignment, while, continue, break, and exit expressions.
This document defines serialization of the W3C XQuery 1.0 and XPath 2.0 Data Model (XDM), which is the data model of at least XML Path Language (XPath) 2.0, XSL Transformations (XSLT) Version 2.0, and XQuery 1.0: An XML Query Language, and any other specifications that reference it.
Serialization is the process of converting an instance of the XQuery 1.0 and XPath 2.0 Data Model into a sequence of octets. Serialization is well-defined for most data model instances.
XML Schema Part 2: Datatypes defines a number of primitive and derived datatypes, collectively known as built-in datatypes. This document defines operations on these datatypes as well as the two datatypes defined in 1.3 xdt:anyAtomicType and xdt:untypedAtomic and the two totally ordered subtypes of
xs:duration defined in 9.2 Two Totally Ordered Subtypes of Duration, for use in XQuery, XPath, XSLT and related XML standards. This document also discusses operators and functions on nodes and node sequences as defined in the XQuery 1.0 and XPath 2.0 Data Model for use in XQuery, XPath, XSLT and other related XML standards.
This document describes possible strategies for tokenizing the XML Path Language (XPath) 2.0 and XQuery 1.0: An XML Query Language languages, and is provided as a helpful guide to those who are designing an implementation for these languages, and as background material for the normative EBNF found in the language specifications. In the future this document may be expanded to cover more general parsing strategies.