Loading TOC...

xdmp.nodeInsertBefore

xdmp.nodeInsertBefore(
   $sibling as Node,
   $new as Node
) as null

Summary

Adds an immediately preceding sibling to a node.

Parameters
$sibling The sibling node to be preceded by the new node.
$new The new node to be inserted.

Usage Notes

Attribute nodes cannot be preceded by non-attribute nodes. Non-attribute nodes cannot be preceded by attribute nodes. Element nodes cannot have document node children. Document nodes cannot have multiple roots. On-the-fly constructed nodes cannot be updated.

Example

// create a document

declareUpdate();
xdmp.documentInsert("/example.xml", fn.head(xdmp.unquote(
    '<a><b>bbb</b></a>')));

******
// add a c node before the b node

declareUpdate();
xdmp.nodeInsertBefore(cts.doc("/example.xml").xpath("/a/b"),
    fn.head(xdmp.unquote('<c>ccc</c>')).root);

******
// look at the new document

cts.doc("/example.xml");
 =>
<?xml version="1.0" encoding="UTF-8"?>
<a><c>ccc</c><b>bbb</b></a>

Comments

    Powered by MarkLogic Server 7.0-4.1 and rundmc | Terms of Use | Privacy Policy