Loading TOC...

xdmp:node-insert-after

xdmp:node-insert-after(
   $sibling as node(),
   $new as node()
) as empty-sequence()

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.

Example

  xdmp:document-insert("/example.xml",
    <a><b>bbb</b></a>);
  xdmp:node-insert-after(doc("/example.xml")/a/b,
    <c>ccc</c>);
  doc("/example.xml")
 =>
  <a><b>bbb</b><c>ccc</c></a>

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

Comments

The commenting feature on this page is enabled by a third party. Comments posted to this page are publicly visible.
  • Is there a way to add an empty attribute (boolean attribute)? The following inserts myattr="" and I just want myattr by itself. xdmp:node-insert-after(fn:doc($blah)/form/@class, attribute myattr {})
    • There is no such thing in XML as an attribute with no value. You can, as you observed, create one whose value is an empty string, but you can't just leave the value off entirely. That's part of the XML standard. See, for example, https://www.w3.org/TR/2006/REC-xml11-20060816/#sec-starttags.