Skip to main content


developerWorks  >  XML | Information Management  >

Process XML using XQuery

Learn to more easily and naturally search your XML data with XQuery 1.0

developerWorks

Level: Introductory

Nicholas Chase (nicholas@nicholaschase.com), Author

24 Sep 2002
Updated 27 Mar 2007

Register now or sign in using your IBM ID and password.

For years developers have used SQL to retrieve data from structured sources such as relational databases. But what about unstructured and semi-structured sources, such as XML data? To be viable as a data source, XML needed a means to conveniently retrieve the data. XQuery provides this means, allowing developers to write a statement that both extracts data and (if necessary) structures the results as XML. This tutorial shows you how to use XQuery to retrieve information from an XML document stored in an XQuery-enabled database. It also explains the ways in which XPath changes with version 2.0, and what those changes mean for data management.

In this tutorial

As XML matures as a format for storing data, the importance of an SQL-like language to retrieve information from a non-structured format such as XML documents grows. XML Query, or XQuery, is a response to this requirement. It utilizes several different structures and ideas, including significant enhancements to XPath that were developed for XSLT 2.0.

With XQuery, you can select very precise sets of data from an XML document or documents, and output an XML structure in response. It also includes sophisticated type management and the ability to create queries that adapt to different situations.

This tutorial guides you through the process of creating and understanding different types of queries available with XQuery and the changes in XPath 2.0.


Objectives

  • Review brief explanations of XQuery basics.

  • Use XQuery with an IBM DB2 V9 database for XQuery queries of stored XML.

  • Use FOR-LET-WHERE-ORDER-RETURN (FLWOR) statements in a manner similar to SQL.

  • Examine how XPath expressions select specific nodes from an XML document.

  • Look at sequences, which replace XPath 1.0's node-sets, and some of the operations and functions that can act on them.

  • Examine more advanced constructions available in an XQuery expression.

  • Explain XQueryX, the XML-structured form of XQuery that corresponds to the human-readable form.

Prerequisites

You should be familiar with XML. An understanding of XPath 1.0 is helpful, but not required

The output for all queries is shown in the tutorial, so it's not necessary to actually run them in order to understand the concepts discussed. If, however, you do want to run some of the queries, you can download and install IBM DB2 version 9, which includes PureXML™ capabilities that make it possible to embed XQuery in an SQL statement. The code in this tutorial was tested on DB2 Enterprise 9.

You can download a trial version of DB2 9: DB2 Enterprise 9 or DB2 Express-C 9, a no-charge version of the DB2 Express 9 data server.


System requirements

You'll need JavaScript enabled in your browser.



Duration

Under one hour


Formats

html, pdf


Share this....

digg Digg this story del.icio.us del.icio.us Slashdot Slashdot it!


Back to top


Document options

Document options requiring JavaScript are not displayed


My developerWorks needs you!

Connect to your technical community