Primitive XML generator for node.js
JavaScript Makefile
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
.jshintrc
.project
.travis.yml
History.md
License
Makefile
README.md
package.json

README.md

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