xml-the-good-parts

convert a subset of XML into JSON

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

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

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

MIT