MarkLogic 12 EA 1 Product Documentation
xdmp.nodeInsertAfter

xdmp.nodeInsertAfter(
   sibling as Node,
   new as Node
) as null

Summary

Adds an immediately following sibling to a node.

Parameters
sibling The sibling node to be followed by the new node.
new The new node to be inserted.

Usage Notes

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

If you want to add a named node to a JSON document in JavaScript, use the NodeBuilder API to construct a named node.

Example

// assume a document created with:
// declareUpdate();
// xdmp.documentInsert("/example.json",
// {"a":"aa","b":"bb"});
//
declareUpdate();
for (var x of fn.doc("/example.json") ) {
  var n = new NodeBuilder();
  var node = n.addNode({"c": ["ab", "cd"]}).toNode().xpath("./array-node('c')");
  xdmp.nodeInsertAfter(x.root.xpath("./b"), node);
    };

// /example.json now looks like:
// {"a":"aa", "b":"bb", "c":["ab", "cd"]}

Example

//  assume a document created with:
//    declareUpdate();
//    xdmp.documentInsert("/example.json",
//    {"a":"aa","b":"bb"});
//
// Add a new named node to a JSON document
//
declareUpdate();
var newnode = new NodeBuilder();
newnode.addNode( {"new":["array", "content"]});
var named = newnode.toNode().xpath("./array-node('new')");
for (var x of fn.doc("/example.json") ) {
 xdmp.nodeInsertAfter(x.root.a, named);
};

//
// /example.json now looks like this:
// {"a":"aa", "new":["array", "content"], "b":"bb"}

Powered by MarkLogic Server | Terms of Use | Privacy Policy