XQuery |
XQuery is a query language (with some programming language features) that is designed to query collections of XML data. It is semantic similarity 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 has not yet achieved the status of a W3C Recommendation, but a number of implementations are available in various states of completeness.
= 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. The FLWOR expression is named after its five clauses: 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. It also lacks full text search capability. These features are both under active development for a subsequent version of the language.
= Examples =
The sample XQuery code below lists the unique speakers in each act of Shakespeare s play Hamlet.
<html><head/><body> { for $act in doc( hamlet.xml )//ACT let $speakers := distinct-values($act//SPEAKER) return <span> <h1>{ $act/TITLE/text() }</h1> <ul> { for $speaker in $speakers return <li>{ $speaker }</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) { $x * 2 }
To write a full query that says Hello World you write the expression:
Hello World
=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
=External links=
*[http://www.w3.org/XML/Query W3C XML Query (XQuery)] *[http://www.w3.org/TR/xquery/ XQuery 1.0: An XML Query Language] *[http://www.xquery.com XQuery.com: Specifications, Articles, Mailing List, and Vendors] *[http://www.stylusstudio.com/xquery_primer.html XQuery Primer: Learn XQuery in Ten Minutes, by. W3C XQuery co-editor, Dr. Michael Kay] *[http://www.datadirect.com/developer/xquery/index.ssp XQuery Developer Central]
Portions borrowed with permission from the book XML Hacks (O Reilly Media).
Previous version based on an article at the [http://fr.wikipedia.org/wiki/XML_Query French language Wikipedia].|
|