What Is XQuery?


XQuery is a fairly new language for querying XML data. It was designed from the ground up by the XML Query Working Group of the W3C with the sole purpose of querying data stored in XML format. As mentioned before, it is essentially a superset of XPath 2.0 that gives it all the features of

XPath 2.0 plus a long list of additional features. The great thing about XQuery is that it was built to work with all XML documents, whether they are untyped, typed, or a combination of the two. In all cases, its job is to query data stored in XML format. It does this by using the XPath navigational functionality.

XQuery Use Cases

Application areas for XQuery can be classified broadly as follows:

  • q XQuery for query and analysis-XQuery is excellent for querying huge chunks of data and provides the capability to filter, sort, order, and repurpose the required information. Typical applications include querying XML documents that represent semistructured information, name-value pair property bags, analysis of application logs, transaction logs and audit logs to identify potential application errors and security issues, and so on.

  • q XQuery for application integration-As organizations move away from proprietary application integration approaches and start adopting standards-based application integration approaches, the need for transforming data from internal application-specific formats to standard exchange formats is gaining more focus. Because of its ability to construct and transform XML data, XQuery caters to this need. One typical use of XQuery in the application-integration domain is translating the vocabulary used by one application that uses a native XML database relational data source into a language used by another application that uses an XML relational data format.

Advantages of XQuery

In addition to building on top of XML querying technologies such as XPath, and XSLT, XQuery also provides a number of advantages:

  • q It is easy to learn if knowledge of SQL and XPath is present.

  • q When queries are written in XQuery, they require less code than queries written in XSLT do.

  • q XQuery can be used as a strongly typed language when the XML data is typed, which can improve the performance of the query by avoiding implicit type casts and provide type assurances that can be used when performing query optimization.

  • q XQuery can be used as a weakly typed language for untyped data to provide high usability.

  • q Because XQuery requires less code to perform a query than does XSLT, maintenance costs are lower.

  • q XQuery is supported by major database vendors.

Structure of an XQuery Expression

An XQuery expression consists of two sections-a prolog and a body. A prolog can in turn contain a namespace declaration subsection. Namespace declarations are used to define a mapping between prefix and namespace URI, thereby enabling you to use the prefix instead of the namespace URI in the query body. You can also refer to element names without the prefix by binding a default namespace for element names, using the declare default namespace declaration.

The body of an XQuery expression contains query expressions that define the result of the query. It can, for example, be the signature FLWOR expression (see the "FLWOR Expressions" section in this chapter), an XPath 2.0 expression, or another XQuery expression such as a construction or arithmetic expression.




Professional XML
Professional XML (Programmer to Programmer)
ISBN: 0471777773
EAN: 2147483647
Year: 2004
Pages: 215

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net