1.0.2 • Published 3 years ago

simplify-xml-js v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

Simplify Output from xml-js

1. Move _text property to actual property value

const simplify = require('simplify-xml-js')

// output from xml-js:
simplify({
    name: { _text: 'john doe'}
})

// becomes:
{
    name: 'john doe'
}

2. Remove namespaces from the property names

const simplify = require('simplify-xml-js')

// output from xml-js:
simplify({
    'form12:name': { _text: 'john doe'}
})

// becomes:
{
    name: 'john doe'
}

3. Remove attributes and decleartions

const simplify = require('simplify-xml-js')

// output from xml-js:
simplify({
    person: {
        _attributes: {
            xmlns: 'http://somecompany.com/format.xsd'
        },
        name: { _text: 'john doe'}
    }
})

// becomes:
{
    person: { name: 'john doe' }
}

4. Simplify values in array

const simplify = require('simplify-xml-js')

// output from xml-js:
simplify({
    phones: [
        {
            _text: '01245'
        },
        {
            _text: '05879'
        }
    ]
})

// becomes:
{
    phones: [ '012345', '05879' ]
}