Monday, September 7, 2009

XQuery

XQuery is a query language (with some programming language features) that is designed to query collections of XML. 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 for XML is like SQL for databases. XQuery 1.0 is an extension of XPath2.0. It supplements XPath with a SQL-like "FLWOR expression" for performing joins. XQuery is a W3C Recommendation. XQuery is supported by all the major database engines (IBM, Oracle, Microsoft, etc.). The language also provides syntax allowing new XML documents to be constructed. 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 uses "smiley faces" to begin and end comments. This cheerful notation was originally suggested by Jeni Tennison. Here is an example of a comment:

 (: Thanks, Jeni! :)

XQuery uses input functions to identify the data to be queried. There are two input functions:

doc()                  returns an entire document, identifying the document by a Universal Resource Identifier (URI). 
                          To be more precise, it returns the document node.

collection()       returns a collection, which is any sequence of nodes that is associated with a URI. 
                          This is often used to identify a database to be used in a query.

The document node does not have explicit syntax in XML, but XQuery provides an explicit document node constructor.

The query document { ... } creates an empty document node.

    document {

            <?xml-stylesheet type="text/xsl" href="c:\temp\double-slash.xslt"?>,
              <!—I love this book! —>,
            <book year="1977">
                    <title>Harold and the Purple Crayon</title>
                    <author>
                    <last>Johnson</last>
                    <first>Crockett</first>
                </author>
                    <publisher>HarperCollins Juvenile Books</publisher>
                    <price>14.95</price>
              </book>
        }