Databases Reference
In-Depth Information
JSONiq and XSPARQL
There are two proposed language extensions to XQuery: JSONiq, which adds the abil-
ity to query JSON documents as well as XML structures, and XSPARQL, which allows
RDF data stores to be queried using XQuery. Some of the features can be imple-
mented using standard XQuery functions, but there are additional benefits to extend-
ing the XQuery language definition to include these features.
5.2.5
Updating documents with XQuery updates
As you may recall from section 5.2.1, we talked about how when new XML documents
are loaded into a native XML database, every element is immediately indexed. If you
think about it, you'll see that this can be an expensive process, especially when you
have large documents that also contain many full-text structures that must be re-
indexed each time the document is saved.
To make saving documents with small changes easier, the W3C has provided a stan-
dard for updating one or more elements within an XML document without having to
update the entire document and the associated indexes. The update operations are
insert —Insert a new element or attribute into a document.
delete —Delete an element or attribute in a document.
replace —Replace an element or attribute in a document with a new value.
rename —Change the name of any element or attribute to a new name.
transform —Transform an element into a new format without changing the
underlying structure on disk.
For example, to change the price of a specific topic in your database, the code might
look like figure 5.7.
XQuery update operations weren't part of the original 2006 XQuery 1.0 specifica-
tion, and at this point you might see topics and XML systems that haven't taken advan-
tage of the full specification. Some systems provide a method of updating XML , but
use a nonstandard method of doing so. Update operations are critical to make it easy
replace value of node
doc('books.xml')//book[ISBN='12345']/price with 39.95
The XML file
of books
The topic you
want to update
The new
price
Figure 5.7 A sample XQuery replace statement that changes the
price of a topic with a specific ISBN number to a new price.
replace value of node is placed before the element and with
is placed before the new price. The net effect is that you can update
a specific element without the overhead of replacing and re-indexing
the entire document.
Search WWH ::




Custom Search