XQuery has been getting a lot of traction for working with XML databases, but its weakest link perhaps has been limitations for writing to the databases it works with. Applications have sometimes had to create multiple copies of XML databases or write back an entire table for a simple data change. However, this is changing with XQuery Update Facility (XUF), a new standard working its way through the last stages with the XML Query Working Group of the W3C. XUF adds the ability to change XML documents that are accessed via XQuery.
"In general XUF introduced a nice optimization to simplify a couple of interesting use cases," said Carlos Innocenti, senior XML program manager at DataDirect. One is the ability to transform and change in place a very large XML document. A company or agency might have a large data dump on a disk, with no access to the mainframe that generated the files. They may need to update this data in place without duplicating the data.
In another case, an organization might need to transform a document to conform to a new data structure standard. XUF allows the coder to focus on the differences between the format specifications rather than completely replicating the data and then adding new data. Carlos Innocenti, Senior XML program manager at DataDirect said this makes the coding more effective and provides a productivity boost.
XQuery takes an XPath Data Model (XDM) instance and returns an XDM instance as a result. An XQuery 1.0 statement never modifies an existing node, although it is possible to create new nodes with constructor expressions.
XUF adds updating expressions for inserting, deleting, replacing or renaming a node. These expressions can be nestled recursively to other XQuery expressions. The XUF spec defines the places in which each type of expression can be used.
New extensions to the XQuery processing model include a pending updates list, a set of update operations for updating primitives and routines.
Implementations of XUF include:
CWI Monet DB: http://monetdb.cwi.nl/
DataDirect Data XQuery: http://www.datadirect.com/products/xquery/index.ssp
ETH Zurich's MXQuery: http://www.mxquery.org
Oracle Berkeley DB XML: http://www.oracle.com/database/berkeley-db/xml/index.html
XMLmind Qizx: http://www.xmlmind.com/qizx/qizx.html
XUF Specification: https://www.w3.org/TR/xquery-update-10/
XQuery Update for the impatient: http://www.xmlmind.com/_tutorials/XQueryUpdate/index.html
Xavier Franc presents a quick yet comprehensive practical introduction to the XQuery Update extension, while highlighting some of its peculiarities
Testing XQuery Update Facility 1.0: http://www.xmlplease.com/xquery-update
Jesper Tverskov gives a technical overview that explains the steps to using XUF. It explains the basics of updates and describes some of the cautions to be aware of.
XQuery Update Use Cases for DB2 pureXML in the health care, business, financial and IT industries:
Tutorial for learning about the various ways to modify XML, including XML stored in memory or a DB2 XML database.