Created
January 13, 2014 10:24
-
-
Save kaero/8397832 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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