XQuery

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 was developed by the XML Query working group of the W3C. The work was closely coordinated with the development of XSLT 2.0 by the XSL Working Group; the two groups shared responsibility for XPath 2.0, which is a subset of XQuery 1.0. XQuery 1.0 became a W3C Recommendation on January 23, 2007.

"The mission of the XML Query project is to provide flexible query facilities to extract data from real and virtual documents on the World Wide Web, therefore finally providing the needed interaction between the Web world and the database world. Ultimately, collections of XML files will be accessed like databases". [cite web|url=http://lists.w3.org/Archives/Public/www-tag/2003Oct/0115.html|title=cited by J.Robie
first=|last=W3C|date=2003-10-25
]

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; 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, encoded in [http://www.ibiblio.org/xml/examples/shakespeare/hamlet.xml hamlet.xml]

<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>

All XQuery constructs for performing computations are 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"

This style is common in functional programming languages. However, unlike most functional programming languages, XQuery doesn't support higher-order functions.

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 and XSLT compared

Scope

Although XQuery was initially conceived as a query language for large collections of XML documents, it is also capable of transforming individual documents. As such, its capabilities overlap with XSLT, which was designed expressly to allow input XML documents to be transformed into HTML or other formats.

The XSLT 2.0 and XQuery standards were developed by separate working groups within W3C, working together to ensure a common approach where appropriate. They share the same data model, type system, and function library, and both include XPath 2.0 as a sublanguage.

Origin

The two languages, however, are rooted in different traditions and serve the needs of different communities. XSLT was primarily conceived as a stylesheet language whose primary goal was to render XML for the human reader on screen, on the web (as web template language), or on paper. XQuery was primarily conceived as a database query language in the tradition of SQL.

Because the two languages originate in different communities, XSLT is stronger in its handlingof narrative documents with more flexible structure, while XQuery is stronger in its data handling,for example when performing relational joins.

Versions

XSLT 1.0 appeared as a Recommendation in 1999, whereas XQuery 1.0 only became a Recommendation in early 2007; as a result, XSLT is at present much more widely used. Both languages have similar expressive power, though XSLT 2.0 has many features that are missing from XQuery 1.0, such as grouping, number and date formatting, and greater control over XML namespaces.cite web|url=http://idealliance.org/proceedings/xtech05/papers/02-03-01/|title=Comparing XSLT and XQuery|first=Michael|last=Kay|date=May 2005] cite web|url=http://www.xml.com/pub/a/2005/03/09/xquery-v-xslt.html|title=Comparing XSLT and XQuery|first=J. David|last=Eisenberg|date=2005-03-09] cite web|url=http://www.xmlhack.com/read.php?item=1080|title=XQuery, XSLT "overlap" debated|date=2001-02-23|first=Michael|last=Smith] . Many of these features are planned for XQuery 1.1. cite web|url=http://www.w3.org/TR/xquery-11-requirements/|title=XQuery 1.1 requirements]

Any comparison must take into account the fact that XSLT 1.0 and XSLT 2.0 are very different languages. XSLT 2.0, in particular, has been heavily influenced by XQuery in its move to strong typing and schema-awareness.

Strengths and weaknesses

Usability studies have shown that "XQuery" is easier to learn than XSLT, especially for users with previous experience of database languages such as SQL. [Usability of XML Query Languages. Joris Graaumans. SIKS Dissertation Series No 2005-16, ISBN 90-393-4065-X] This can be attributed to the fact that XQuery is a smaller language with fewer concepts to learn, and to the fact that programs are more concise. It is also true that XQuery is more orthogonal, in that any expression can be used in any syntactic context. By contrast, XSLT is a two-language system in which XPath expressions can be nested in XSLT instructions but not vice versa.

XSLT is currently stronger than XQuery for applications that involve making small changes toa document (for example, deleting all the NOTE elements). Such applications are generally handledin XSLT by use of a coding pattern that involves an identity template that copies all nodes unchanged, modified by specific templates that modify selected nodes. XQuery has no equivalent to this coding pattern, though in future versions it will be possible to tackle such problems using the update facilities in the language that are under development. cite web|url=http://www.w3.org/TR/xqupdate/|title=XQuery Update Facility]

Another facility lacking from XQuery is any kind of mechanism for dynamic binding or polymorphism. The absence of this capability starts to become noticeable when writing large applications, or when writing code that is designed to be reusable in different environments. XSLT offers two complementary mechanisms in this area: the dynamic matching of template rules, and the ability to override rules using xsl:import, that make it possible to write applications with multiple customization layers.

The absence of these facilities from XQuery is a deliberate design decision: it has the consequence that XQuery is very amenable to static analysis, which is essential to achieve the level of optimization needed in database query languages. This also makes it easier to detect errorsin XQuery code at compile time.

The fact that XSLT 2.0 uses XML syntax makes it rather verbose in comparison to XQuery 1.0. However, many large applications take advantage of this capability by using XSLT to read, write, or modify stylesheets dynamically as part of a processing pipeline. The use of XML syntax also enables the use of XML-based tools for managing XSLT code. By contrast, XQuery syntax is more suitable for embedding in traditional programming languages such as Java or C#. If necessary, XQuery code can also be expressed in an XML syntax called XQueryX. The XQueryX representation of XQuery code is rather verbose and not convenient for humans, but can easily be processed with XML tools, for example transformed with XSLT stylesheets. cite web|url=http://www.w3.org/TR/xqueryx/|title=XML Syntax for XQuery (XQueryX)] cite web|url=http://saxonica.blogharbor.com/blog/_archives/2007/1/20/2665644.html|title=Saxon diaries: How not to fold constants|author=Michael Kay]

Future work

Currently, two major extensions to the XQuery are under development by W3C:
* XQuery 1.0 and XPath 2.0 Full-Text [ [http://www.w3.org/TR/xquery-full-text/ XQuery and XPath Full Text 1.0 ] ]
* XQuery Update Facility

Work has started on XQuery 1.1. Planned new features are listed in a new requirements document. [ [http://www.w3.org/TR/xquery-11-requirements/ XML Query (XQuery) 1.1 Requirements ] ]

Scripting (procedural) extension for XQuery is also being designed. [ [http://www.w3.org/TR/xquery-sx-10-requirements/ XQuery Scripting Extension 1.0 Requirements ] ]

Further information

* Querying XML: XQuery, XPath, and SQL/XML in context. Jim Melton and Stephen Buxton. Morgan Kaufmann, 2006. ISBN 1558607110.
* XQuery. Priscilla Walmsley. O'Reilly Media, 2007. ISBN 0596006349.
* XQuery: The XML Query Language. Michael Brundage. Addison-Wesley Professional, 2004. ISBN 0321165810.
* 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 [http://www.stylusstudio.com/xquery_flwor.html XQuery FLWOR] Expression. Dr. Michael Kay (W3C XQuery Committee), 2005.

Implementations

* [http://www.altova.com/products/xmlspy/xml_editor.html Altova XMLSpy 2007] is a widely used commercial XML editor and development environment for modeling, editing, transforming, and debugging XML-related technologies. It supports XQuery, and includes an XQuery Debugger, a code generator for mapping between schemas, and AltovaXML Query Processor which handles both XSLT 2 and XML Query 1.0.
* [http://www.basex.org/ BaseX] a native, open-source XQuery processor, allowing interactive XQuery input and evaluation.
*Sedna XML Database High performance XQuery engine, designed for production grade software handling gigabytes of XML data. Many different language APIs. Open source.
* [http://saxon.sourceforge.net/ Saxon XSLT and XQuery Processor] — by Michael Kay; open source version available, supports extensions written in Java or C#
* [http://www.galaxquery.org Galax] - An open source OCaml XQuery implementation supporting various extensions; especially suited for academic XQuery implementations
* [http://www.gnu.org/software/qexo/ Qexo] - open source, written in Java with Kawa
* MarkLogic Server, an XML database that uses XQuery and is optimized for large collections of XML document content
* [http://www.datadirect.com/products/xquery/ DataDirect XQuery] - platform-independent XQuery engine for most relational databases
* OpenLink Virtuoso
* BEA AquaLogic ALDSP - XQuery for data integration
* [http://msdn2.microsoft.com/en-us/library/ms189075.aspx Microsoft SQL Server 2005]
* [http://www-306.ibm.com/software/data/db2/xml/ DB2 9]
* [http://www.xmlmind.com/qizx Qizx] - high-performance XQuery database engine (Qizx/db), with an open-source version (named Qizx/open).
* [http://support.x-hive.com/xquery/index.html X-Hive/DB's] XQuery implementation.
* [http://monetdb.cwi.nl/XQuery/ MonetDB/XQuery] - An open source XQuery processor on top of the [http://monetdb.cwi.nl/Home/index.html MonetDB] relational database system, with support for W3C XQuery Update Facility.
* [http://xqilla.sourceforge.net/ XQilla] - An open source ( [http://www.apache.org/licenses/LICENSE-2.0.html ASL2.0] ) XQuery processing library with support for the latest XQuery Update features. XQilla is written in C++ and includes a command line executable shell to execute queries against XML content stored on a local filesystem. This library is actively developed and part of a supported [http://oracle.com/ Oracle] product, [http://www.oracle.com/database/berkeley-db/xml/ Berkeley DB XML] .
* [http://www.zorba-xquery.org/ Zorba] - Zorba is a general purpose XQuery processor implementing in C++ a W3C family of specifications (i.e. XQuery 1.0 and XQuery Update Facility). It is not an XML database. The query processor has been designed to be embeddable in a variety of environments such as other programming languages extended with XML processing capabilities, browsers, database servers, XML message dispatchers, or smartphones. Zorba is available under the Apache license v2.
* many more [http://www.w3.org/XML/Query#implementations XQuery implementations] (some free/open source).

References

External links

* [http://www.w3.org/XML/Query W3C XML Query (XQuery)]
* [http://www.ibiblio.org/xml/examples/shakespeare/hamlet.xml hamlet.xml] Hamlet in XML Format
* [http://www.jcp.org/en/jsr/detail?id=225 JSR 255] XQuery API for Java (XQJ) Java Specification Request
* [http://www.w3.org/TR/xqupdate/ XQuery Update facility working draft]
* [http://www.cafeconleche.org/slides/xmlsig/xquery/index.html XQuery] (presentation - as HTML slides)
* [http://www.datadirect.com/developer/xquery/xquerybook/ XQuery: A Guided Tour] - an 80 page introduction to XQuery
* [http://www.datadirect.com/developer/xquery/topics/xqj_tutorial/index.ssp XQuery for Java (XQJ) Tutorial]
* [http://www.SQLSummit.com/XQueryProv.htm List of XQuery Engines and Processors at SQLSummit.com]
* [http://www.x-query.com X-Query.com: Specifications, Articles, Mailing List, and Vendors]
* [http://www.webservicessummit.com/People/DFlorescu.htm Webcast and Podcast: Interview with Dr. Daniela Florescu, co-inventor of Quilt and co-editor of W3C XML Query Language (XQuery) specifications]
* [http://www.datadirect.com/developer/xquery/index.ssp XQuery Developer Central]
* [http://blogs.datadirect.com/jonathan_robie/ Jonathan Robie's XQuery Blog] - Jonathan is an Editor of several XQuery Specifications
* [http://blogs.datadirect.com/jonathan_bruce/ Jonathan Bruce Blog - Convergence HQ: XQuery, Java, .NET]
* [http://www.xqueryfunctions.com/xq/ FunctX XQuery Functions] - open source pure XQuery function library, tested with [http://saxon.sourceforge.net/ Saxon] and [http://www.xquery.com/ Data Direct XQuery]
* [http://xquery.typepad.com Discovering XQuery Blog]
* [http://www.xquery.com XQuery.com]
* [http://www.diva-portal.org/diva/getDocument?urn_nbn_se_liu_diva-3717-1__fulltext.pdf An XML-based Database of Molecular Pathways] XQuery Speed / Performance comparisons between eXist, X-Hive, Sedna and Qizx/open
* [http://www.xqdt.org/ XQuery Development Tools for Eclipse (XQDT)]
* [http://www.w3schools.com/xquery/default.asp XQuery tutorial]

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

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


Wikimedia Foundation. 2010.

Игры ⚽ Поможем решить контрольную работу

Look at other dictionaries:

  • XQUERY — steht für XML Query Language und bezeichnet eine vom W3C spezifizierte Abfragesprache für XML Datenbanken. XQuery benutzt eine an XSLT, SQL und C angelehnte Syntax und verwendet XPath sowie XML Schema für sein Datenmodell und seine… …   Deutsch Wikipedia

  • XQuery — steht für XML Query Language und bezeichnet eine vom W3C spezifizierte Abfragesprache für XML Datenbanken. XQuery benutzt eine an XSLT, SQL und C angelehnte Syntax und verwendet XPath sowie XML Schema für sein Datenmodell und seine… …   Deutsch Wikipedia

  • Xquery — steht für XML Query Language und bezeichnet eine vom W3C spezifizierte Abfragesprache für XML Datenbanken. XQuery benutzt eine an XSLT, SQL und C angelehnte Syntax und verwendet XPath sowie XML Schema für sein Datenmodell und seine… …   Deutsch Wikipedia

  • XQuery — est un langage de requête informatique permettant non seulement d extraire des informations d un document XML, ou d une collection de documents XML, mais également d effectuer des calculs complexes à partir des informations extraites et de… …   Wikipédia en Français

  • Xquery — est un langage de requête informatique permettant non seulement d extraire des informations d un document XML, ou d une collection de documents XML, mais également d effectuer des calculs complexes à partir des informations extraites et de… …   Wikipédia en Français

  • XQuery — XQuery  язык запросов, разработанный для обработки данных в формате XML. XQuery использует XML как свою модель данных. XQuery 1.0 был разработан рабочей группой XML Query в составе организации W3C. Эта работа координируется другой рабочей… …   Википедия

  • XQuery — es un lenguaje de consulta diseñado para colecciones de datos XML. Es semánticamente similar a SQL, aunque incluye algunas capacidades de programación. XQuery 1.0 fue desarrollado por el grupo de trabajo de Consulta XML del W3C. El trabajo fue… …   Wikipedia Español

  • XQuery Update Facility — XQuery Update XQuery Update Facility est une extension de XQuery, un langage de requête XML standardisé par le W3C. Cette extension fournit les moyens de modifier des instances du modèle de données XQuery ou XPath 2 (documents ou bases de… …   Wikipédia en Français

  • XQuery Update — Facility est une extension de XQuery, un langage de requête XML standardisé par le W3C. Cette extension fournit les moyens de modifier des instances du modèle de données XQuery ou XPath 2 (documents ou bases de données). XQuery Update est une… …   Wikipédia en Français

  • XQuery Update Facility — is an extension to the XML Query language, XQuery. It provides expressions that can be used to make changes to instances of the XQuery 1.0 and XPath 2.0 Data Model.It became a W3C Candidate Recommendation on 14 March 2008.Implementations*… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”