Skip to content

mstn/xml2js-clean

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

clean xml2js output following some user defined heuristics (based on work by Tristian Flanagan)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published