XQuery
(Page 1 of 5 )
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).
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:
http://saxon.sourceforge.net/
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:
http://java.sun.com
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.
Next: Testing Saxon-B >>
More XML Articles
More By McGraw-Hill/Osborne
|
This article is excerpted from chapter nine of the book XML DeMYSTiFieD, written by Jim Keogh and Ken Davidson (McGraw-Hill/Osborne, 2005; ISBN: 0072262109). Check it out today at your favorite bookstore. Buy this book now.
|
|