xml-the-good-parts

1.2.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i xml-the-good-parts

Weekly Downloads

2

Version

1.2.0

License

MIT

Last publish

Collaborators

  • nopersonsmodules