Currently there is no W3C standard available for Updates within XQuery. XQuery is expected to get an
update syntax as there is already a task force and a set of use cases, but so far nothing has been
published. Therefore
Updates can be invoked using one of the functions described below. The query evaluation is independent of the update syntax and follows snapshot semantics. Conceptually the single update operations are generated, cached and not applied until after query execution. There are currently no checks for conflicting updates within one query.
xhive:create-library($uri as xs:string) as empty-sequence() creates a library with the given
$uri. If parent libraries mentioned in the path are missing, they are created too
(the function behaves like UNIX mkdir -p).
There is a set of insert functions that follow the same style. The functions are
xhive:insert-into($where as node(), $what as item()*) as empty-sequence(),
xhive:insert-into-as-first($where as node(), $what as item()*) as empty-sequence(),
xhive:insert-into-as-last($where as node(), $what as item()*) as empty-sequence(),
xhive:insert-before($where as node(), $what as item()*) as empty-sequence(),
xhive:insert-after($where as node(), $what as item()*) as empty-sequence()
Applying an insert function inserts the given items ($what) relative to $where:
into it as last, as first, before or after it, respectively. insert-into and
insert-into-as-last behave identical.
Atomic values within $what are converted into text nodes like in element constructors.
If $where is not a node or the empty sequence, an error is raised.
xhive:insert-document($uri as xs:string, $document as document-node()) as empty-sequence()
inserts the given $document at $uri. If there is already a document
at $uri an error is raised.
xhive:remove($nodes as node()*) as empty-sequence() removes the given $nodes
from their parents. xhive:delete() is an alias to this function.
xhive:remove-library($uri as xs:string) as empty-sequence() removes the library at
$uri with all it's children.
xhive:rename-to($what as node(), $newName as xs:QName) as empty-sequence() renames the given
node to $newName. This function raises an error if it's target is not an
attribute node, an element node, a processing instruction or a document node. Additionally
processing instructions can only be renamed to unqualified localnames, e.g. QNames without a
namespace URI. To construct a QName, use the standard function
fn:QName($uri as xs:string?, $qname as xs:string) as xs:QName.
xhive:replace-value-of($where as node(), $newContents as item()*) as empty-sequence() removes
all children of $where and replaces them with $newContents.
Similar to xhive:delete($where/item()),xhive:insert-into($where, $newContents).
Examples:
for $book in document('bib.xml')/bib/book
where @year < 1990
return
xhive:remove($book)
for $book in document('bib.xml')/bib/book,
$review in document('http://example.com/reviews.xml')//review
where @isbn = $book/@isbn
return
xhive:insert-into($book, $review)
xhive:insert-document('/lib/newfile.xml',
document {
<root>
...
</root>
}
)