The XML query language (XQuery) is a complete query language for XML databases. It stands to XML databases as SQL stands to relational ones. An XML database is a collection of (related) XML documents.
XQuery works on sequences, not on node sets as XPath. A sequence contains items which are either XML nodes (such as elements and attributes) or atomic values (like strings and numbers). The relationship between XPath and XQuery consists in the fact that XPath expressions are used in XQuery queries (xqueries). Hence, we may consider XPath as a syntactic fragment of XQuery.
A typical xquery works as follows:
Some of the above steps are optional. For instance, an xquery may avoid the loading of a document and the retrieval of sequences with XPath expressions, and, instead, it may create, process, and output its own sequences. In fact, XQuery can be used as a (Turing-complete) programming language that manipulates item sequences, possibly using functions defined by the user. In these pages we will focus on XQuery as an XML query language.
An XQuery processor is a software that evaluates xqueries. See the XQuery resources page for a list of XQuery processors. Saxon is a good example. In order to evaluate with Saxon the query contained in the file xquery.xql, type the following:
java net.sf.saxon.Query xquery.xql