
xdmp.nodeInsertAfter( sibling as Node, new as Node ) as null
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. |
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.
// 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"]}
// 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"}
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.