Skip to main content


developerWorks  >  XML  >

Advancing with XQuery: Develop application idioms

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

developerWorks

Level: Intermediate

James R. Fuller (jim.fuller@webcomposite.com), Technical Director, FlameDigital Limited & Webcomposite s.r.o.

30 Sep 2008

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

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.

In 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.


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 will need JavaScript enabled in your browser.

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.



Duration

1 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