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]

Advancing with XQuery: Develop application idioms

Work with extension functions, unit tests and assertions, recursion and sorting, and higher-order functions

James R. Fuller (jim.fuller@webcomposite.com), Technical Director, FlameDigital Limited & Webcomposite s.r.o.
Photo of Jim Fuller
Jim Fuller has been a professional developer for 15 years, working with several blue-chip software companies in both his native USA and the UK. He has co-written a few technology-related books and regularly speaks and writes articles focusing on XML technologies. He is a founding committee member for XML Prague and was in the gang responsible for EXSLT. He spends his free time playing with XML databases and XQuery. Jim is technical director for a few companies (FlameDigital, Webcomposite s.r.o.) and can be reached at jim.fuller@webcomposite.com.

Summary:  The XQuery specification is well over a year old now. A surfeit of solid implementations combined with (if developer chatter is anything to go by) marked new interest, seems to indicate that XQuery is finally experiencing higher adoption rates. Possibly this is due to developers starting to figure out how to utilize XQuery within a rich mixture of XML technologies (such as XML databases. XSLT, XML Schema). Learn how to use XQuery beyond its original role as an XML query language and apply it toward the development of middleware and Web applications.

Date:  30 Sep 2008
Level:  Intermediate PDF:  A4 and Letter (137 KB | 35 pages)Get Adobe® Reader®

Activity:  13243 views
Comments:  

Before you start

Before you examine XQuery code samples, here's how to get the most of this tutorial, and instructions on how to install and use the included source code (see Downloads).

About this tutorial

This tutorial is about using XQuery to develop applications and middleware. It outlines some of XQuery's limitations while you develop applications, gives you practical advice along the way on how to manage these limitations as well as highlights where XQuery makes it easy or difficult. The bulk of the tutorial then builds on these principles, as it presents a series of programmatic idioms commonly found in application development:

  • Use of extension functions
  • Unit testing and assertions
  • Recursion and sorting
  • Higher-order functions

Each section comes with accompanying source code examples (see Downloads).


Objectives

The goal of this tutorial is to give you a practical grounding in how to develop applications with XQuery. I try to provide cut-and-paste code that you can re-use in your own application-development efforts, though it is my hope that these code examples will inspire you to reconsider using XQuery for more than querying XML.


Prerequisites

This tutorial is written for developers who have a general familiarity with XML technologies as well as some cursory XSLT or Query experience. The programmatic idioms presented can be found in one form or another in a lot of computer programming languages, and I make no claim of invention on them. This re-use should mean that for most readers, you'll see familiar constructions—albeit set in the context of XQuery programming.


System requirements

You must install Michael Kay's Saxon XSLT and XQuery processor SA aware version to execute code examples. As you need the Saxon-SA version, you must register for a 30-day trial (for example, at the time of this writing version 9.1SA was used in testing). Many of the code examples use higher-order functions to take advantage of specific Saxon-SA extension functions (specifically, the saxon:function()).

Place all the Java™ Archive (JAR) files and license file in Saxon under the /lib directory.

To run examples you can invoke Saxon from the command line or use the included Ant build file (which I used to test the code examples). If you do use the build file, then you should also install the latest Apache Ant, and take care to amend the saxon.lib.dir property to point to the /lib directory containing Saxon JARs. To test whether Saxon is working properly, run the Ant target checkSaxon, which will successfully process when Saxon is installed properly. All Ant targets generate result output into the /result directory.

1 of 10 | 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
ArticleID=341929
TutorialTitle=Advancing with XQuery: Develop application idioms
publish-date=09302008
author1-email=jim.fuller@webcomposite.com
author1-email-cc=dwxed@us.ibm.com

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.