This tutorial introduced you to XQuery, which is a query language that makes it relatively easy to extract specific elements from an XML document. XQuery is analogous to SQL in the relational database world in that it allows you to construct queries that you execute against XML documents to retrieve matching data. In this lesson, you learned how to construct a variety of different kinds of queries using XQuery. You learned that XQuery is closely linked to another XML technology, XPath. You wrapped up the tutorial by working your way through a couple of interesting XQuery examples, which hopefully reinforced what you learned throughout the lesson as a whole.


Is XQuery supported in any web browsers?

Not yet. Unfortunately, none of the major browsers support XQuery just yet, although rumors abound that XQuery support is underway for upcoming releases.

How does XQuery differ from XPath?

XPath is a language used for addressing within XML documents. XQuery is a query language used to filter data within XML documents. XPath can also be used for pattern matching on XML documents and in fact serves that role within XQuery. Fundamentally, the two languages differ more in purpose than in design. XQuery solves a larger problem and incorporates XPath toward that end. Addressing and Linking XML Documents covers XPath in detail.


The Workshop is designed to help you anticipate possible questions, review what you've learned, and begin learning how to put your knowledge into practice.



How do the queries //vehicle[color='red'] and //vehicle[color='red']/color differ?


How do you indicate that a query entity is an attribute rather than an element?


How do you embed query results within other XML code?

Quiz Answers


The first of the two queries returns vehicle elements that contain a color element set to red. The second of the two queries returns the color elements that are children of those same vehicle elements.


Names that begin with @ are treated as attributes; names with no qualifier are elements.


Enclose the query results in {}.



Download an implementation of XQuery, such as Saxon, and use it to write some queries against your own XML documents. You can download a free open source version of Saxon from http://www.saxonica.com/.

by BrainBellupdated