tagstream

streamOfXmlText.pipe(tagstream()).pipe(streamOfXmlEvents)

tagstream wraps node-expat in a through-stream so you can perform XML parsing as part of a pipeline using event-stream's various fun operators, e.g. map and join, and your own through-streams.

var es = require('element-stream'),
    tagstream = require('tagstream');

es.pipeline(
  input,
  tagstream(),
  // streams to transform XML events into whatever you want
  output
);

See test/demo.js for one example, which extracts the text from between XML tags.

Each datum carried by the data event out of the tag stream is an array. Depending on the XML event, it'll be one of these:

  • [ 'start', tagName, attributes ]
  • [ 'end', tagName ]
  • [ 'text', text ]

Back-pressure is applied as expected. Due to some event-stream magic, if everything in the pipeline behaves properly then the first input stream will be paused whenever a write fails on the final output stream. That's what I wanted when I started writing this module, so I'm pretty happy.

npm install to ensure tap is present, then npm test.