Builds XML documents in a lazy way.
const E = require('libxmljs-lazy-builder')
const libxml = require('libxmljs')
const doc = new libxml.Document()
const elem = E("root", {},
E("kit", {color: "brown"}),
"mars",
E("kat"))(doc)
elem.toString()
// => '<root><kit color="brown"/>mars<kat/></root>'
npm install libxmljs-lazy-builder --save
(You can name it arbitrarily.) This function generates a function which takes a libxml.Document object and returns a libxml.Element object.
A child can be a string or an another E() element. You can specify zero or more children.
Please note that you need to call the returned value from E() with a Document object to get an actual Element object. So, the whole structure should be something like:
const doc = new libxml.Document()
const elem = E("x", {}, E("y", {}, ...), ...)(doc)
Please see the test script in the repository.
MIT
Toru Hisai @torus