Dealing with XML data can be frustrating. Especially if you have a whole-lot of it. Most XML readers work on the entire XML document as a String: this can be problematic if you need to read very large XML files. With xml-flow, you can use streams to only load a small part of an XML document into memory at a time.
xml-flow has only one dependency, sax-js. This means it will run nicely on windows environments.
$ npm install xml-flow
xml-flow tries to keep the parsed output as simple as possible. Here's an example:
<root>
<person>
<name>Bill</name>
<id>1</id>
<age>27</age>
</person>
<person>
<name>Sally</name>
<id>2</id>
<age>29</age>
</person>
<person>
<name>Kelly</name>
<id>3</id>
<age>37</age>
</person>
</root>
var fs = require('fs')
, flow = require('xml-flow')
, inFile = fs.createReadStream('./your-xml-file.xml')
, xmlStream = flow(inFile)
;
xmlStream.on('tag:person', function(person) {
console.log(person);
});
{name: 'Bill', id: '1', age: '27'}
{name: 'Sally', id: '2', age: '29'}
{name: 'Kelly', id: '3', age: '37'}
MIT