Home arrow XML arrow XQuery


XQuery speeds up the process of finding information contained in an XML document, which is very handy when dealing with long XML documents. This article, the first of two parts, will teach you how to write XQuery expressions. It is excerpted from chapter nine of the book XML DeMYSTiFieD, written by Jim Keogh and Ken Davidson (McGraw-Hill/Osborne, 2005; ISBN: 0072262109).

Author Info:
By: McGraw-Hill/Osborne
Rating: 5 stars5 stars5 stars5 stars5 stars / 10
February 09, 2006
  1. · XQuery
  2. · Testing Saxon-B
  3. · How XQuery Works
  4. · A Walkthrough of an XQuery
  5. · Constructors

print this article

(Page 1 of 5 )

A customer calls you asking a question about her order. You need to quickly access her order; however, all orders are stored in a very long XML document. Itís too time-consuming to search through each line of the XML document. What do you do? You could panic and have an unhappy customer, or you can create an XQuery to electronically search for and display the customerís order.

Think of XQuery as your electronic assistant who knows where to find any information in an XML document as fast as your computer will allow. Your job is to use the proper expression to request the information. XQuery interprets your request and retrieves the information that you need from the XML document.

The way you use XQuery is similar to how you use SQL to access information from a relational database. The relational database is like an XML documentóboth contain lots of information, making it inefficient to search by hand.

In this chapter, youíll harness the power of XQuery by learning how to write expressions that enable you to tap into the vast treasure trove of information stored in an XML document.

Getting Started

There are a few things that youíll need to do before you write your first XQuery expression. XQuery is an extension of XPath; therefore, make sure that you read Chapter 6 before moving ahead with this chapter. Youíll also need an XQuery processor. An XQuery processor is the software thatís like an electronic assistant who searches an XML document for information you request. Skip this section if you already have installed an XQuery processor; otherwise, read on and learn how to install one.

Several XQuery processors are available. Some are freeware or open source, and others are commercial software products. Letís save a few dollars. Download the Saxon-B version 8, which is an open source XQuery processor, at:


Saxon-B is a zip file. Download it to c:\saxon and then unzip the file. Thatís all you need to do to install Saxon-B.

Saxon-B is a Java program. Therefore, youíll also need to have a runtime version of Java installed on your computer. Youíll find a free, downloadable copy at:


Download the latest version of Java 2 Standard Edition (J2SE) and follow the installation instructions that come with the downloaded file. You donít need to know anything about Java to run Saxon-B with the examples we show in this chapter. Take note of where you install the Java runtime. You will need to know this to execute the samples.

blog comments powered by Disqus

- Open XML Finally Supported by MS Office
- XML Features Added to Two Systems
- Using Regions with XSL Formatting Objects
- Using XSL Formatting Objects
- More Schematron Features
- Schematron Patterns and Validation
- Using Schematron
- Datatypes and More in RELAX NG
- Providing Options in RELAX NG
- An Introduction to RELAX NG
- Path, Predicates, and XQuery
- Using Predicates with XQuery
- Navigating Input Documents Using Paths
- XML Basics
- Introduction to XPath

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials