2.0.1 • Published 3 years ago
gexode v2.0.1
gexode
Primitive XML generator for node.js
Example
const { doc, elem } = require(gexode);
const car = doc(elem('car', {wheels: 4}).text('Volvo'));
car.toString();renders as:
<?xml version='1.0' encoding='UTF-8'?>
<car wheels='4'>Volvo</car>Generator mode
gexode can also be used as a generator
const { generator } = require('gexode');
const { header, start, el, end } = generator({ pretty: true });
function* cars() {
yield* header();
yield* start('cars');
yield* el('car', { wheels: 4 }, 'Volvo');
yield* end();
}
Array.from(cars()).join('');renders as:
<?xml version='1.0' encoding='UTF-8'?>
<cars>
<car wheels='4'>Volvo</car>
</cars>API
generator(options)
options-{ pretty, selfClosing }ifprettyis truthy intendations are generate ifselfClosingis truthy empty tags are self closeing<likeThis/>header- generate XML headerel(name, attribute, text)- generate a node with attributes (optional) and text (optional), close the node automaticallystart(name, attribute)- likeelbut do not close the nodeend- close recently opened node
License
MIT