<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/xdmp.nodeInsertBefore.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>xdmp.nodeInsertBefore</api:function-name><api:suggest>xdmp.nodeinsertbefore</api:suggest><api:suggest>xdmp</api:suggest><api:suggest>nodeinsertbefore</api:suggest><api:function-link mode="xquery" fullname="xdmp:node-insert-before">/apidoc/8.0/xdmp:node-insert-before.xml</api:function-link><api:function mode="javascript" name="nodeInsertBefore" type="builtin" lib="xdmp" category="UpdateBuiltins" hidden="false" bucket="MarkLogic Built-In Functions" prefix="xdmp" namespace="http://marklogic.com/xdmp" fullname="xdmp.nodeInsertBefore"><api:summary>
  Adds an immediately preceding sibling to a node.
</api:summary><api:params><api:param name="sibling" type="node()"><api:param-description>
    The sibling node to be preceded 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>
  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.
</api:usage><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
// create a document 

declareUpdate();
xdmp.documentInsert("/example.xml", xdmp.unquote(
    '&lt;a&gt;&lt;b&gt;bbb&lt;/b&gt;&lt;/a&gt;').next().value);

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

declareUpdate();
xdmp.nodeInsertBefore(cts.doc("/example.xml").xpath("/a/b"),
    xdmp.unquote('&lt;c&gt;ccc&lt;/c&gt;').next().value.root);

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

cts.doc("/example.xml");
 =&gt;
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;a&gt;&lt;c&gt;ccc&lt;/c&gt;&lt;b&gt;bbb&lt;/b&gt;&lt;/a&gt;
</pre></api:example></api:function></api:function-page>