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 }
ifpretty
is truthy intendations are generate ifselfClosing
is truthy empty tags are self closeing<likeThis/>
-
header
- generate XML header -
el(name, attribute, text)
- generate a node with attributes (optional) and text (optional), close the node automatically -
start(name, attribute)
- likeel
but do not close the node -
end
- close recently opened node
License
MIT