gexode

Primitive XML generator for node.js


Keywords
xml
License
MIT
Install
npm install gexode@2.0.1

Documentation

NPM version Build Status Dependency Status

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 } if pretty is truthy intendations are generate if selfClosing 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)- like el but do not close the node

  • end - close recently opened node

License

MIT