Following functions are used to traverse the document tree.
doc
Returns the document node. doc
can be called from anywhere in the document.
doc()
const { create } = require('xmlbuilder2');
const root = create().ele("root");
const doc = root.doc();
first
Returns the first child node.
first()
const { create } = require('xmlbuilder2');
const root = create().ele("root")
.ele("node1").up()
.ele("node2").up();
const node1 = root.first();
last
Returns the last child node.
last()
const { create } = require('xmlbuilder2');
const root = create().ele("root")
.ele("node1").up()
.ele("node2").up();
const node2 = root.last();
next
Returns the next sibling node.
next()
const { create } = require('xmlbuilder2');
const root = create().ele("root")
.ele("node1").up()
.ele("node2").up();
const node1 = root.first();
const node2 = node1.next();
prev
Returns the previous sibling node.
prev()
const { create } = require('xmlbuilder2');
const root = create().ele("root")
.ele("node1").up()
.ele("node2").up();
const node2 = root.last();
const node1 = node2.prev();
root
Returns the root element node. Root element node is the document element node of
the XML document. root
can be called from anywhere in the document.
root()
const { create } = require('xmlbuilder2');
const grandChild = create().ele("root").ele("child").ele("grandchild");
const root = grandchild.root();
up
Returns the parent element node.
up()
const { create } = require('xmlbuilder2');
const grandChild = create().ele("root").ele("child").ele("grandchild");
const child = grandchild.up();
const root = child.up();