1.2.0 • Published 10 years ago

xml-the-good-parts v1.2.0

Weekly downloads
2
License
-
Repository
github
Last release
10 years ago

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)

Example - extract all links

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