article Related Topics:
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:

  1. Logical/physical data independence
  2. Declarative
  3. High level
  4. Side-effect free
  5. Strongly typed 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"

Applications


Below are a few examples of how XQuery can be used:

  1. Extracting information from a database for a use in web service.
  2. Generating summary reports on data stored in an XML database.
  3. Searching textual documents on the Web for relevant information and compiling the results.
  4. Selecting and transforming XML data to XHTML to be published on the Web.
  5. Pulling data from databases to be used for the application integration.
  6. 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


External links


''Portions borrowed with permission from the book "XML Hacks" (O'Reilly Media).

Previous version based on an article at the French language Wikipedia.

W3C standards | XML-based standards | Query languages

XQuery | XML Query | XQuery | XQuery | XQuery | XQuery | XQuery

 

This article is licensed under the GNU Free Documentation License. It uses material from the "XQuery".

Home Pageartsbusinesscomputersgameshealthhospitalshomekids & teensnewsphysiciansrecreationreferenceregionalscienceshoppingsocietysportsworld