node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

gexode

Build Status Dependency Status NPM version

gexode

Primitive XML generator for node.js

Example

var gexode = require(gexode), doc = gexode.doc, elem = gexode.elem;
 
var car = doc(elem('car', {wheels: 4}).text('Volvo'));
car.write(out);

renders as:

<?xml version='1.0' encoding='UTF-8'?>
<car wheels='4'>Volvo</car>

Streaming mode

gexode can be also used in streaming mode

var gexodeStream = require('gexode').stream;
var xml = gexodeStream(writeableStream);
 
xml.header();
xml.start('cars');
xml.el('car', {wheels: 4}, 'Volvo');
xml.end();
 

renders as:

<?xml version='1.0' encoding='UTF-8'?>
<cars>
<car wheels='4'>Volvo</car>
</cars>

API

stream(out, options)

  • out is a writeble stream (network response, file etc.)

  • options - { pretty, selfClosing } if pretty is truthy intendations are generate if selfClosing is truthy empty tags are self closeing <likeThis/>

  • stream.header - generate XML header

  • stream.el(name, attribute, text)- generate a node with attributes (optional) and text (optional), close the node automatically

  • stream.start(name, attribute)- like el but do not close the node

  • stream.end - close recently opened node

License

MIT