xml-the-good-parts

convert a subset of XML into JSON

npm install xml-the-good-parts
7 downloads in the last week
10 downloads in the last month

xml-the-good-parts

Convert a subset of XML into JSON.

If you have tidy XML that has tags but no attributes, then with this module you can convert it into JSON.

If someplace it has more complex stuff, it'll probably barf. NO WARRANTY EXPRESSED OR IMPLIED

Example - convert to json

var XMLTGP = require('xml-the-good-parts')
var JSONStream = require('JSONStream')

process.stdin
  .pipe(XMLTGP())
  .pipe(XMLTGP.parse())
  .pipe(XMLTGP.jsonize())
  .pipe(JSONStream.stringify())
  .pipe(process.stdout)
var XMLTGP     = require('../')
var through    = require('through')

process.stdin
  .pipe(XMLTGP.tokenize())
  .pipe(XMLTGP.attrs())
  .pipe(through(function (node) {
    if(node.tag = 'a' && node.attrs.href)
      this.queue(node.attrs.href + '\n')
  }))
  .pipe(process.stdout)

or as cli tool.

npm install -g xml-the-good-parts

xml-the-good-parts < evil.xml > nice.json

Known Bugs/TODO

This does not support escaped quotes in attributes. Probably you should use sax or trumpet instead.

License

MIT

npm loves you