@fedyou/xml-parser
v1.1.0
Published
Xml parser fast and simple
Readme
Xml Parser
It converts JSON objects to xml, is lightweight, fast and simple, and does not use any dependencies.
Works for both
commonjsandesmodules.
Use
const xmlParser = require('@fedyou/xml-parser')
const json = {
'@elem': 'elem',
'@atts': { hidden: false, position: 20, content: 'Some text' },
'@childs': [
{
'@elem': 'child',
'#': 'text',
// "#": 20,
// "#": true,
'@childs': [
{
'@elem': 'sub-child'
}
]
}
]
}
// By default the formatting is set to false
const xml = xmlParser('root', json, { format: true })
console.log(xml)Result:
<?xml version='1.0' encoding='utf-8'?>
<root>
<elem hidden='false' position='20' content='Some text'>
<child>text
<sub-child>
</child>
</elem>
</root>Another way to use JSON as an array:
const json = [
{
'@elem': 'child'
},
{
'@elem': 'child',
'@atts': { boolean: true }
}
]Abbreviations
@elem: @
#: #
@atts: $
@childs: &
