This is a library designed to render js objects as xml. Its not made to parse or otherwise edit existing xml/html structures.
This is a library designed to render js objects as xml. Its not made to parse or otherwise edit existing xml/html structures. For that and perhaps as a compliment to this you can use jsdom or xml2js for editing existing markup.
this will do a good job rendering json as xml but apis that require xml expect odd things mostly related to elements with attributes and implicit array like keys that make formatting your json a little tricky.
var jsonxml = ;var xml =console;
text contentbeef tacohot!fish tacomildhiweakis a nice thing to sayi am another not special child nodeSun Sep 26 2010 17:27:29 GMT-0700 (PDT)
optionsis optional. it can be true (add generic xml header) or an object. If an object, valid options are:
xmlHeadercan either be boolan (add generic
<?xml …?>header) or an object. If an object valid options are:
standaloneif true, the
<?xml …?>gets an additional attribute
docTypeif defined gets added as the
<!DOCTYPE …>contents (unescaped).
prettyPrintif truthy the output gets a rudimentary pretty print (good for debugging, don't expect too much)
indentspecify what unit you would like to indent by (spaces, tabstop, nothing - pass an empty string)
removeIllegalNameCharactersreplace illegal XML element Name characters with '_'
"" & < >
]]>) in input text
I made this because i wanted to abstract away the fact that antiquated external systems require post data as xml and i wanted to expose a standard js calling api like my other interfaces.
I did not want to instantiate an entire dom to perform simple updates to tags in lower level functions (like injecting api keys) when top level api call specific functions start building the xml string.