Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Process XML using XQuery

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

Nicholas Chase has been involved in Web site development for companies such as Lucent Technologies, Sun Microsystems, Oracle, and the Tampa Bay Buccaneers. Nick has been a high school physics teacher, a low-level radioactive waste facility manager, an online science fiction magazine editor, a multimedia engineer, and an Oracle instructor. More recently, he was the Chief Technology Officer of Site Dynamics Interactive Communications in Clearwater, Florida, USA, and is the author of three books on Web development, including Java and XML From Scratch (Que) and the upcoming Primer Plus XML Programming (Sams). He loves to hear from readers and can be reached at nicholas@nicholaschase.com.

Summary:  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.

Date:  27 Mar 2007 (Published 24 Sep 2002)
Level:  Intermediate PDF:  A4 and Letter (766 KB | 39 pages)Get Adobe® Reader®

Activity:  20133 views
Comments:  

Before you start

Develop skills on this topic

This content is part of a progressive knowledge path for advancing your skills. See Querying XML from Java applications

This tutorial teaches you how to use XQuery to retrieve information from an XML document. It also explains the ways in which XPath changes with version 2.0, and what those changes mean for data management.

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

What is this tutorial about?

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. It progresses as follows:

  • XQuery basics: Provides an overview of the topic, with brief explanations of each topic.
  • Using XQuery with DB2: Walks you through setting up an IBM® DB2® V9 database for XQuery queries of stored XML.
  • FLWOR statements: Explains the use of FOR-LET-WHERE-ORDER-RETURN statements, which are used in a manner similar to SQL.
  • XPath expressions: Examines the ways in which XPath expressions select specific nodes from an XML document.
  • Sequences: Looks at sequences, which replace XPath 1.0's node-sets, and some of the operations and functions that can act on them.
  • Additional features: Explains some of the more advanced constructions available in an XQuery expression.
  • XQueryX: Explains the XML-structured form of XQuery that corresponds to the human-readable form.

Prerequisites

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.

1 of 11 | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=XML, Information Management
ArticleID=756147
TutorialTitle=Process XML using XQuery
publish-date=03272007
author1-email=nicholas@nicholaschase.com
author1-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.