Loading TOC...

MarkLogic 10 Product Documentation
NodeBuilder.addDocument

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

Summary

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

Parameters
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.

Example

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

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

Example

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

let builder = new NodeBuilder();
builder.addDocument(makeDocument);
builder.toNode();

// 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.