gexode

2.0.1 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i gexode

Weekly Downloads

1

Version

2.0.1

License

MIT

Unpacked Size

6.13 kB

Total Files

5

Last publish

Collaborators

  • pirxpilot