by Thomas Erl
 XML Core Technology
divider
 Data Access with
 XQuery
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.
 

return to homepage


SOA: Principles
of Service Design

by Thomas Erl

An in-depth guide dedicated to service engineering with a thorough exploration of the design principles that comprise the service-orientation design paradigm (including a comparison with object-orientation).


Service-Oriented Architecture:
Concepts, Technology, and Design

by Thomas Erl

The first "how-to" guide to building SOA, providing coverage of WS-* specifications, .NET and J2EE platforms, and step-by-step processes for service-oriented analysis and design.
Service-Oriented Architecture:
A Field Guide
to Integrating
XML and Web Services

by Thomas Erl

The best-selling guide to service-oriented integration, providing hundreds of integration strategies and over sixty best practices.

For more information about either book, visit: www.soabooks.com

About SOA Systems

SOA Systems Inc. provides strategic SOA consulting services and offers a comprehensive SOA training program.

For more information see:

•  www.soasystems.com

•  www.soatraining.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.

   
   
Home   Copyright © 1999-2007 SOA Systems Inc.