Created
March 16, 2011 17:41
-
-
Save robrighter/872911 to your computer and use it in GitHub Desktop.
js object to xml quick and dirty
This file contains hidden or 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
function js2xml(js, wraptag){ | |
if(js instanceof Object){ | |
return js2xml(Object.keys(js).map(function(key){return js2xml(js[key], key);}).join('\n'), wraptag); | |
}else{return ((wraptag)?'<'+ wraptag+'>' : '' ) + js + ((wraptag)?'</'+ wraptag+'>' : '' );} | |
} | |
//try it | |
var output = js2xml({ | |
boosh: '1', | |
is: '2', | |
a: '3', | |
test:'4', | |
another: { | |
internal: 'stuff', | |
yea: 'whoot' | |
} | |
}); | |
console.log(output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment