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 profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

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:  17833 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



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