<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/xdmp.nodeInsertAfter.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>xdmp.nodeInsertAfter</api:function-name><api:suggest>xdmp.nodeinsertafter</api:suggest><api:suggest>xdmp</api:suggest><api:suggest>nodeinsertafter</api:suggest><api:function-link mode="xquery" fullname="xdmp:node-insert-after">/apidoc/8.0/xdmp:node-insert-after.xml</api:function-link><api:function mode="javascript" name="nodeInsertAfter" type="builtin" lib="xdmp" category="UpdateBuiltins" hidden="false" bucket="MarkLogic Built-In Functions" prefix="xdmp" namespace="http://marklogic.com/xdmp" fullname="xdmp.nodeInsertAfter"><api:summary>
  Adds an immediately following sibling to a node.
</api:summary><api:params><api:param name="sibling" type="node()"><api:param-description>
    The sibling node to be followed by the new node.
  </api:param-description><api:param-name>sibling</api:param-name><api:param-type>Node</api:param-type></api:param><api:param name="new" type="node()"><api:param-description>
    The new node to be inserted.
  </api:param-description><api:param-name>new</api:param-name><api:param-type>Node</api:param-type></api:param></api:params><api:return>null</api:return><api:usage>
  <p xmlns="http://www.w3.org/1999/xhtml">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.</p>
  <p class="javascript" xmlns="http://www.w3.org/1999/xhtml">If you want to add a named node to a JSON document
  in JavaScript, use the <code>NodeBuilder</code> API to construct a 
  named node.</p>
</api:usage><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
// 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"]}
 
</pre></api:example><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
//  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"}
 
</pre></api:example></api:function></api:function-page>