2.0.1 • Published 1 year ago

gexode v2.0.1

Weekly downloads
11
License
MIT
Repository
github
Last release
1 year ago

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

2.0.1

1 year ago

2.0.0

2 years ago

1.0.0

7 years ago

0.1.0

11 years ago

0.0.3

11 years ago

0.0.2

12 years ago

0.0.1

13 years ago