Home XML Specs WS-* Specs Other Specs

Data Access with XQuery
by Thomas Erl

The XQuery specification establishes a comprehensive data query language, designed specifically for XML documents. XQuery is aligned with and overlaps considerably with release 2.0 of the XPath specification. XQuery uses the XPath language to define data source addressing, and even adds some new XPath extensions.
XQuery statements can be isolated into independent functions. Functions can then be logically organized into modules.
A module can contain a collection XQuery functions that can be imported into other modules.
XQuery expressions can be embedded within an XML document (in which case they are enclosed within braces).
XQuery is often compared to the Structured Query Language (SQL). In fact, some XQuery features are even derived from traditional SQL statements. A significant characteristic of XQuery is that it enables you to perform a search across multiple XML repositories with a single query statement. This establishes a data source independence that broadens the application of XQuery beyond that of SQL.
View Large Image

SOA Design Patterns
by Thomas Erl

Foreword by Grady Booch

With contributions from David Chappell, Jason Hogg, Anish Karmarkar, Mark Little, David Orchard, Satadru Roy, Thomas Rischbeck, Arnaud Simon, Clemens Utschig, Dennis Wisnosky, and others.

Web Service Contract Design & Versioning
for SOA

by Thomas Erl, Anish Karmarkar, Priscilla Walmsley, Hugo Haas, Umit Yalcinalp, Canyang Kevin Liu, David Orchard, Andre Tost, James Pasley

Foreword by David Chappell


SOA Principles
of Service Design

by Thomas Erl

Service-Oriented Architecture:
Concepts, Technology, and Design

by Thomas Erl

Service-Oriented Architecture:
A Field Guide
to Integrating
XML and Web Services

by Thomas Erl

For more information about these books, visit: www.soabooks.com

More Resources

•  www.soapatterns.org

•  www.whatissoa.com

•  www.soaprinciples.com

•  www.soamagazine.com

•  www.soamethodology.com

•  www.soaglossary.com

•  www.soa-manifesto.org


SOA Certified Professional

The books in this series are part of the official curriculum for the SOA Certified Professional program.

For more information:

•  www.soaschool.com

•  www.soacp.com



Depending on the nature of the data you are searching, and the type of query expression you need to build, you can choose from one of several available expression formats. These include:
FLWR (pronounced “flower”), which provides a series of keywords that are comparable to those used by SQL.
Path expressions, which allow you to access elements and attributes of an input document.
Element constructors that enable the dynamic creation of new XML elements and values.
Conditional expressions that can add complex logic to query statements using the well-known if-then-else construct.
Quantified expressions that allow for the inclusion of quantifying logic. Using keywords, such as some and every, submitted test expressions result in either “false” or “true”.
For our example we’ll be building a FLWR query expression using the for, where and return keywords. The for clause below provides a variable that is bound to the book element of the books.xml document. The values that will be output are defined by the subsequent XQuery clauses.
for $x in document("books.xml")//book
The where fragment is very similar to the SQL WHERE clause, in that it defines the search criteria. In this case, we are searching for all books written by “Joe Smith”.
where $x/author = "Joe Smith"
In order to define what data from the queried XML tree we actually want returned, XQuery provides the return keyword (much like an SQL SELECT statement). In response to our query, we’d like to get the titles written by Joe Smith.
return $x/title
When the following XQuery statement:
for $x in document("books.xml")//book where $x/author = "Joe Smith" return $x/title
… queries this document:
<inventory>
   <book category=”Fiction”>
     <title>Joy of Integration</title>
     <author>Joe Smith</author>
   </book>
   <book category=”Non-Fiction”>
     <title>Integration for Dummies</title>
     <author>John Doe</author>
   </book>
</inventory>
…it returns the following result:
<title>Joy of Integration</title>
With numerous types of expressions at its disposal, the XQuery specification can be used to create complex query logic. Key features to look out for include support for XSD data types, XPath functions, SQL aggregation functions, and many other SQL features, such as grouping, joins and sorting.

Copyright © 2004-2009 SOA Systems Inc.