XQuery
Encyclopedia : X : XQ : XQU : XQuery
XQuery is a query language (with some programming language features) that is designed to query collections of XML data. It is semantically similar to SQL.
XQuery 1.0 is being developed by the XML Query working group of the W3C. The work is closely coordinated with the development of XSLT 2.0 by the XSL Working Group; the two groups share responsibility for XPath 2.0, which is a subset of XQuery 1.0. XQuery 1.0 became a W3C Candidate Recommendation on November 3, 2005.
Features
XQuery provides the means to extract and manipulate data from XML documents or any data source that can be viewed as XML, such as relational databases or office documents.
XQuery uses XPath expression syntax to address specific parts of an XML document. It supplements this with a SQL-like "FLWOR expression" for performing joins. A FLWOR expression is constructed from the five clauses after which it is named: FOR, LET, WHERE, ORDER BY, RETURN.
The language also provides syntax allowing new XML documents to be constructed. Where the element and attribute names are known in advance, an XML-like syntax can be used; in other cases, expressions referred to as dynamic node constructors are available. All these constructs are defined as expressions within the language, and can be arbitrarily nested.
The language is based on a tree-structured model of the information content of an XML document, containing seven kinds of node: document nodes, elements, attributes, text nodes, comments, processing instructions, and namespaces.
The type system of the language models all values as sequences (a singleton value is considered to be a sequence of length one). The items in a sequence can either be nodes or atomic values. Atomic values may be integers, strings, booleans, and so on: the full list of types is based on the primitive types defined in XML Schema.
XQuery 1.0 does not include features for updating XML documents or databases, as is done by XUpdate. It also lacks full text search capability. These features are both under active development for a subsequent version of the language.
XQuery is a programming language that can express arbitrary XML to XML data transformations with the following features:
- Logical/physical data independence
- Declarative
- High level
- Side-effect free
- Strongly typed language
Examples
The sample XQuery code below lists the unique speakers in each act of Shakespeare's play Hamlet.
<html><head/><body> </h1> <ul> </li> } </ul> </span> } </body></html>XQuery is a functional language consisting entirely of expressions. There are no statements, even though some of the keywords appear to suggest statement-like behaviors. To execute a function, the expression within the body gets evaluated and its value returned. Thus to write a function to double an input value, you simply write:
declare function local:doubler($x)To write a full query that says Hello World you write the expression:
"Hello World"
Applications
Below are a few examples of how XQuery can be used:
- Extracting information from a database for a use in web service.
- Generating summary reports on data stored in an XML database.
- Searching textual documents on the Web for relevant information and compiling the results.
- Selecting and transforming XML data to XHTML to be published on the Web.
- Pulling data from databases to be used for the application integration.
- Splitting up an XML document that represents multiple transactions into multiple XML documents.
XQuery vs XSLT controversy
XQuery and XSLT both have similar goals of allowing input XML documents to be transformed into other formats. Both standards were developed by the same working groups and both are published by the W3C, although XSLT was designed first and seems to have greater acceptance and maturity as of 2006. Both languages are generally accepted as being nearly equally capable of expressing the same transformations.Areas that commonly cited where XQuery is stronger than XSLT:
- ease of use
- optimizability
- strong data typing
- External links comparing the two
Further information
- XQuery from the Experts: A Guide to the W3C XML Query Language. Howard Katz (ed). Addison-Wesley, 2004. ISBN 0-321-18060-7
- An Introduction to the [XQuery FLWOR] Expression. Dr. Michael Kay (W3C XQuery Committee), 2005.
Implementations
- Saxon XSLT and XQuery Processor — an opensource project
- MarkLogic Server
- [DataDirect XQuery] - a high-performance, platform-independent XQuery engine for most relational databases
- OpenLink Virtuoso
- many more [XQuery implementations] (some free/open source).
External links
- [W3C XML Query (XQuery)]
- [XQuery 1.0: An XML Query Language]
- [JSR 255] XQuery API for Java (XQJ) Java Specification Request
- [XQuery] (presentation - as HTML slides)
- [XQuery: A Guided Tour - an 80 page introduction to XQuery]
- [XQuery for Java (XQJ) Tutorial]
- [List of XQuery Engines and Processors at SQLSummit.com]
- [XQuery.com: Specifications, Articles, Mailing List, and Vendors]
- [XQuery Primer: Learn XQuery in Ten Minutes, by. W3C XQuery co-editor, Dr. Michael Kay]
- [Webcast and Podcast: Interview with Dr. Daniela Florescu, co-inventor of Quilt and co-editor of W3C XML Query Language (XQuery) specifications]
- [XQuery Developer Central]
- [Jonathan Robie's XQuery Blog - Jonathan is an Editor of several XQuery Specifications]
- [Jonathan Bruce Blog - Convergence HQ: XQuery, Java, .NET]
- [<oXygen/> XQuery Editor and Debugger]
- [Discovering XQuery Blog]
Previous version based on an article at the [French language Wikipedia].
From Wikipedia, the Free Encyclopedia. Original article here. Support Wikipedia by contributing or donating.
All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.
