Skip to content

Instantly share code, notes, and snippets.

@kaero
Created January 13, 2014 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaero/8397832 to your computer and use it in GitHub Desktop.
Save kaero/8397832 to your computer and use it in GitHub Desktop.
var fs = require('fs'),
util = require('util'),
xamel = require('./'),
Tag = require('./lib/xml').Tag;
/**
* @param {NodeSet} nset
* @returns {Object} plain object
*/
function serializeNodeSet(nset) {
return nset.reduce(function(res, child) {
res.push(child instanceof Tag ? {
name: child.name,
attrs: child.attrs,
children: serializeNodeSet(child.children)
} : child);
return res;
}, []);
}
xamel.parse(fs.readFileSync('./test/data/simple.xml', 'utf8'), function(err, xml) {
var plainObj = serializeNodeSet(xml);
console.log(util.inspect(plainObj, {depth: 100}));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment