NodeBuilder.toNode() as Node
Return the node tree that has been built.
It is an error to call toNode on an incomplete node tree, that is, one with open XML element or document nodes. Undefined is returned when toNode is called on an empty NodeBuilder.
const builder = new NodeBuilder(); builder.startElement('ex:example','http://example.com/ns1'); builder.addText('Some element content here'); builder.endElement(); builder.toNode(); // Returns an XML element node equivalent to the following: // // <ex:example xmlns:ex="http://example.com/ns1"> // Some element content here // </ex:example>
const builder = new NodeBuilder(); builder.startElement('ex:example','http://example.com/ns1'); builder.addText('Some element content here'); builder.toNode(); // Throws an exception because the element "ex:example" is not terminated.
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.