MENU
XQUF
XQuery Update Facility (XQUF) is an extension to XQuery for updating XML documents in place, via insert, delete, replace, and rename expressions, a copy-modify-return transform expression, and an inline update expression usable inside a FLWOR. BaseX is a program that supports XQUF.Each example below updates the following document independently:
ch05-xquf-data.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<a>
<b>Hello</b>
<b>World</b>
</a>insert node
The insert node expression adds one or more nodes into, before, or after a target node. Inserting a sequence of an attribute, a text node, and an element into /a appends them as the last children (attributes are added to the element regardless of position): as first into inserts a node as the first child of the target instead of the last (as last into is equivalent to a plain into): before inserts a node as the preceding sibling of a target node (after inserts it as the following sibling):delete node
Removes one or more target nodes from the document:replace node
Replaces a target node with a new node, including its name and content: replace value of node keeps the target node's name and only replaces its value, so the replacement expression's string value becomes the new content while the element name stays unchanged:rename node
Changes the name of a target node, keeping its content:transform expression: copy ... modify ... return
A copy-modify-return expression binds a variable to a copy of a node, applies a sequence of update expressions to that copy inside modify, and returns the modified copy without touching the original document:copy $v := /a
modify (
rename node $v/b[1] as 'c',
insert node ('Kitty') into $v/b[2]
) return $vupdate expression
An update expression applies update expressions to a node inline, e.g. within the return clause of a for, without a separate copy-modify-return block:for $v in a/b
return $v update delete node text()