Loading TOC...


   content as String|Function,
   [uri as String]
) as This NodeBuilder object


Add a document node to the node tree the builder is building.

content The contents of the document. If the argument is a string, the builder will add a document node containing that string as a text node. If the argument is a function, that function will be executed with the builder as its argument.
uri The document URI.

Usage Notes

Document nodes may only be added to an empty node tree.

There is no relationship between the URI of the document and the nodes that may be added to that document. In particular, "example.xml" could contain JSON nodes, and "example.json" could contain XML nodes.


const builder = new NodeBuilder();
builder.addDocument('simple text document', 'simple.txt');

// Returns a text document node containing "simple text document".


function makeDocument(b) {
  b.addElement('p','Copyright 2014 Joe\'s House of Tech. All Rights Reserved.');

const builder = new NodeBuilder();

// Returns a document node with the following contents:
// <?xml version="1.0" encoding="UTF-8"?>
// <p>Copyright 2014 Joe's House of Tech. All Rights Reserved.</p>

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