Loading TOC...

xdmp:node-insert-child

xdmp:node-insert-child(
   $parent as node(),
   $new as node()
) as empty-sequence()

Summary

Adds a new last child to a node. For XML documents, only element nodes and document nodes can have children. For JSON documents, object nodes and array nodes can have children. Element nodes, object nodes, and array nodes cannot have document node children. Document nodes cannot have multiple roots. On-the-fly constructed nodes cannot be updated. The parameters must specify individual nodes and not node sets.

Parameters
$parent The parent node which will have a new child node.
$new The new child node to be inserted.

Example

(: create a document :)
xdmp:document-insert("/example.xml",
    <a/>);

(: insert a child of a :)
xdmp:node-insert-child(doc("/example.xml")/a,
    <b>bbb</b>);

(: look at the new document :)
fn:doc("/example.xml")
 =>
<?xml version="1.0" encoding="UTF-8"?>
<a><b>bbb</b></a>

Example

(: create a document :)
xdmp:document-insert("/example.xml",
    <a/>);

(: insert an attribute as child of a :)
  xdmp:node-insert-child(doc("/example.xml")/a,
    attribute b { "bbb" });

(: look at the new document :)
fn:doc("/example.xml")
 =>
<?xml version="1.0" encoding="UTF-8"?>
<a b="bbb"/>

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.