Skip to content

Instantly share code, notes, and snippets.

@robrighter
Created March 16, 2011 17:41
Show Gist options
  • Save robrighter/872911 to your computer and use it in GitHub Desktop.
Save robrighter/872911 to your computer and use it in GitHub Desktop.
js object to xml quick and dirty
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