Loading TOC...

MarkLogic 12 EA 2 Product Documentation
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>

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