
xdmp:node-replace( $old as node(), $new as node() ) as empty-sequence()
Replaces a node.
| Parameters | |
|---|---|
| old | The old node, to be replaced. |
| new | The new node. |
If the caller of the function uses function mapping and $old
is an empty sequence, the node-replace function may return an
empty sequence. It will not return an error.
(: create an XML document :)
xdmp:document-insert("/example.xml",
<a><b>bbb</b></a>);
(: replace the b node with a c node :)
xdmp:node-replace(doc("/example.xml")/a/b, <c>ccc</c>);
(: look at the new document :)
fn:doc("/example.xml")
=>
<?xml version="1.0" encoding="UTF-8"?>
<a><c>ccc</c></a>
(: This example shows how to update the root
node of a text format document. Start by
creating a text document. :)
xdmp:document-insert("/mydir/doc.txt",
text{"This is a line of text."} ) ;
(: Update the text node of the text document
by appending another line of text to the
text node. Note that the text node is the
root node of a text document. :)
xdmp:node-replace(doc("/mydir/doc.txt")/text() ,
text{ concat(doc("/mydir/doc.txt")/text(), "
This is another line of text.") } ) ;
doc("/mydir/doc.txt")
=>
This is a line of text.
This is another line of text.
(: create a document :)
xdmp:document-insert("/foo.json", object-node {"foo":"this is a value"});
(: replace the value using xdmp:node-replace :)
xdmp:node-replace(fn:doc("/foo.json")/foo, text{"this is a different value"});
fn:doc("/foo.json")
=>
{"foo":"this is a different value"}
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.