See Also: Home Links Personal Site Blogroll  FriendFeed CV

Tags:

Topic Image

XQuery

In 2004 I attended OSCON in Portland, Oregon and went to a talk on XQuery. These are the notes I made after the session:

This was one of the last sessions I went to (and why I forgot to blog earlier) and was an introdution to XQuery and its possible uses. Was presented by Jason Hunter who turned out to be a real evangelist for the technology. He was very excited about it (and how much money he was going to earn as an expert :-)

XQuery is an W3C coordinated initiative which began in 1999 and is essentially a hybrid of XPath queries, built-in functions and a high-level functional scripting language. The XPath statements return node sets and the scripting language lets you manipulate their content.

XQuery's role is to bind one or more XML and other structured (and semi/unstructured) data stores together, a kind of "SQL for XML". A store provider builds an XQuery interface and that is exposed to external or 3rd-party XQuery engines. There is significant effort from big names like Oracle, IBM, BEA and MS towards XQuery integration.

XQuery isnt just used to query and intergrate data sources, it's also used to transform and present the query results using the scripting language and sequences of output statements (actually 'return's) typically embedded in an XHTML file which is passed through an XQuery engine. Custom functions can be declared within the XQuery script to extend or modularise the XQuery processing.

Here's an example XQL file....

for $i in doc("orders.xml")//Customer
let $name := concat($i/@FirstName, $i/@LastName)
where $i/@ZipCode = 91126
order by $i/@LastName
return
  <Customer Name="{$name}">
    { $i//Order }
  </Customer>

Hunter suggested that everything accomplished using XSLT currently will ultimately be performed through XQuery in its less verbose form, and the format should be easier to both read and write. Will be useful for data-mining apps and should be an enabler of natural-language like query interfaces to and accross structured stores.

There are numerous implementations of XQuery available already: Hunter reccomended eXist, Qizx, Qexo, XQuark. Michael Kay's Saxon also supports XQuery now (along with XSLT 2 and XPath 2), he's split his product in two, one is open-source and free, the other more fully featured and commercial.

The company that Hunter works for (Mark Logic) has just released a free community version of their XQuery engine with a 50MB limit on data volume. This appears to be a solid implementation and will be interesting to experiment with.

other useful resources:


See Also: XML Technologies | Web Development | Notes Index