Read XML into a JSON structure and then convert that JSON back into XML.
npm install xmhellRead XML into a JSON structure and then convert that JSON back into XML.
This library exports 4 functions.
* parse(): same as JSON.parse(), takes a string and returns a javascript object.
* write(): takes an object, a writer (anything with a function called write), and a callback.
Writes the JSON object as XML and then calls the callback when complete.
* escape(): Escapes XML entities.
* unescape(): You get the idea.
Example:
> var XMHell = require('xmhell');
> j = XMHell.parse('\n
{ doc:
{ x: { y: 'abcdefg' },
'#COMMENT': ' comment ' } }
>
> XMHell.write(j, process.stdout, function() { console.log('done!'); });
done!
>
You can provide a function in place of a string in your JSON document and this function will be
called with a writer and a callback to be called upon completion. The provided writer escapes XML
entities.
> var async = function(writer, callback) { writer.write('async & stuff'); callback(); };
> XMHell.write({"a":async}, process.stdout);
async & stuff
Multiple tags by the same name are converted to numbered keys in the json hash.
> XMHell.parse('
{ doc:
{ x: '',
'x 2': '',
'x 3': '',
'x 4': '',
'x 5': '',
'x 6': '' } }
Any trailing numbers are stripped from the key when generating the tag name.
> XMHell.write({'a 9000':1, 'a 3': 2, a:3}, process.stdout);
1
2
3
Comments, cdata and doctypes are expressed using special keys called #COMMENT,#CDATA and #DOCTYPE.
> XMHell.parse('');
{ '#DOCTYPE': 'blah',
'#COMMENT': ' This is a comment ',
'#CDATA': 'yay cdata' }
This parser concentrates on making it possible to represent any valid XML as something in JSON
where it can be manipulated and then converted to XML. It preserves comments and prettyprints the
result with 2 spaces per tab.
No idea, how about you try and find out!
If it makes you feel better, this parser is guaranteed not to generate invalid json.
Sure does!
Converts to:
"feed xmlns=\"http://www.w3.org/2005/Atom\" xmlns:media=\"http://search.yahoo.com/mrss/\" xml:lang=\"en-US\"": {
}
LOL you're joking right?
What did you expect? XMHeaven? Anyway this was
not
my
idea.
Send an invoice.