Highly configurable Object to XML converter for Node.
$ npm install easyxml
var EasyXml = require('easyxml');
var serializer = new EasyXml({
singularizeChildren: true,
allowAttributes: true,
rootElement: 'response',
dateFormat: 'ISO',
indent: 2,
manifest: true
});
var obj = {
items: [{
name: 'one',
_id: 1
}, {
name: 'two',
_id: 2
}, {
name: 'three',
_id: 3
}],
blah: 'http://www.google.com',
when: new Date(),
boolz: true,
nullz: null
};
console.log(serializer.render(obj));
This should output the following XML document:
<?xml version='1.0' encoding='utf-8'?>
<response>
<items>
<item id="1">
<name>one</name>
</item>
<item id="2">
<name>two</name>
</item>
<item id="3">
<name>three</name>
</item>
</items>
<blah>http://www.google.com</blah>
<when>2012-09-25T18:47:39.485Z</when>
<boolz>true</boolz>
<nullz />
</response>
singularizeChildren
: If an array is plural, its children elements will be singularallowAttributes
: String attributes starting with _ will be XML attributesattributePrefix
: Prefix to look for when creating attributesrootElement
: A string to wrap around the rendered XML documentrootArray
: If the root element is an array, this wraps the XML document. Should be pluraldateFormat
: A date format for JS dates, currently accepts ISO, SQL, JSindent
: A number representing the spaces to indent children, use 0 for no whitespacemanifest
: Whether or not to add that XML manifest line to the topunwrappedArrays
: TODO: DocumentfilterNulls
: Should nulls and undefines be removed from the rendered XML
This project is licensed under a Dual BSD/GPL license.