1.1.20 • Published 2 years ago
ut-function.xml2json v1.1.20
ut-function.xml2json - practical XML parsing
Use precompiled template to extract meaningful object from XML junk
Usage
<!-- template.xml -->
<some>
<deep>
<nested>
<structure>${a}</structure>
</nested>
</deep>
<veryVeryLongTagName>${b.c}</veryVeryLongTagName>
<potentially>
<missing>${d}</missing>
</potentially>
<some>
<!-- payload.xml -->
<randomNameSpace:some xmlns:randomNameSpace="http://randomNameSpace.com">
<deep>
<nested>
<structure>value 1</structure>
</nested>
</deep>
<veryVeryLongTagName>value 2</veryVeryLongTagName>
<something>
<weDoNotCareAbout>value 3</weDoNotCareAbout>
</something>
</randomNameSpace:some>
const fs = require('fs');
const parse = require('ut-function.xml2json')(fs.readFileSync('template.xml').toString())
const xml = fs.readFileSync('payload.xml').toString();
async function test() {
// convert xml string to object
await parse(xml)
// { a: 'value 1', b: { c: 'value 2' }, d: undefined }
// convert xml string to JSON
await parse(xml, true)
// '{"a":"value 1","b":{"c":"value 2"},"d":"undefined"}'
// convert parsed xml to object
await parse({
some: {
deep: {
nested: {
structure: 'value 1'
}
},
veryVeryLongTagName: 'value 2'
}
});
// { a: 'value 1', b: { c: 'value 2' }, d: undefined }
}
1.1.20
2 years ago
1.1.19
2 years ago
1.1.18
2 years ago
1.1.17
2 years ago
1.1.16
3 years ago
1.1.15
3 years ago
1.1.14
3 years ago
1.1.13
3 years ago
1.1.9
3 years ago
1.1.12
3 years ago
1.1.11
3 years ago
1.1.10
3 years ago
1.1.8-dfa-0.0
5 years ago
1.1.8
5 years ago
1.1.7
5 years ago
1.1.6
6 years ago
1.1.5
6 years ago
1.1.4
6 years ago
1.1.3
6 years ago
1.1.1
6 years ago
1.1.2
6 years ago
1.1.0
6 years ago