Transform stream for parsing large XML files. It is using SAX module internally. Emits objects: one object per each selected node.
$ npm install sax-stream
Use as any transform stream: pipe request or file stream to it, pipe it downstream to another
transform/writeable stream or handle data event.
var saxStream = require('sax-stream');
request('http://blog.npmjs.org/rss')
.pipe(saxStream({
strict: true,
tag: 'item' // or tags: ['item']
}))
.on('data', function(item) {
console.log(item);
});const {saxStream, tags} = require('sax-stream');
request('http://blog.npmjs.org/rss')
.pipe(saxStream({
strict: true,
tags: ['itemA', 'itemB']
}))
.on('data', ({itemA, itemB}) => {
itemA && console.log('Item A', data);
itemB && console.log('Item B', data);
})
;
// or with a helper:
request('http://blog.npmjs.org/rss')
.pipe(saxStream({
strict: true,
tags: ['itemA', 'itemB']
}))
.on('data', tags({
itemA: data => console.log('Item A', data),
itemB: data => console.log('Item B', data),
}))
;Create passing options object:
omitNsPrefix- if set totrue, removes namespace prefix of elementstag- name of the tag to select objects from XML file (this ortagsis required)tags- name of tags to select objects from XML file (this ortagis required)highWaterMark- size of internal transform stream buffer - defaults to 350 objectsstrict- default to false, iftruemakes sax parser to accept valid XML onlynormalize,lowercase,xmlns,position,strictEntities,noscript- passed to sax parser
MIT