0.0.3 • Published 6 years ago

xml2js-clean v0.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

The package xml2js converts xml to json. In general, the problem is not easy since there are some ambiguities to be addressed. For this reason, xml2js produces a not very clean output.

This package tries to apply some heuristics to clean xml2js output.

Heuristics should be based on some known assumptions on the underlying xml schema.

Users can define their own heuristics, too.

Example

cleanXml(xml, {
  operations: [ // plug in the heuristics to apply
    simplifyArrayValues,
    transformEnglishSingularNamesToArray,
    parseNumericValues,
  ]
});

Input

sample: {
  title: 'fee',
  number: '2.4',
  integer: '399',
  items: {
    item: [ 'foe', 'foo' ]
  },
  entities: {
    entity: [
      { hello: 'world' },
      { hello: 'mum' },
    ]
  }
}

Output

sample: {
  title: 'fee',
  number: 2.4,
  integer: 399,
  items: [ 'foe', 'foo' ],
  entities: [
    { hello: 'world' },
    { hello: 'mum' },
  ]
}

Credits

The idea is discussed in this answer on Stackoverflow and is implemented in this package by Tristian Flanagan. This package is a rewriting of his code to make it more reusable and flexible.

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago

0.0.0

6 years ago