A stripped down fork of https://github.com/hgourvest/node-xml-lite
- This is a pure javascript XML SAX parser for Node.js.
- The specificity of this xml parser is that it can parse a document from a Buffer.
- It relies on iconv-lite to decode the text according to the code page of the document.
- Removed all
SAXParse*
API variants until I have time to rewrite them into aparseStream
API - Exported the raw
XmlParser
class to allow for custom, lightweight parsing jobs (somewhat making up for the removal of theSAXParse*
APIs) - Added TypeScript definition file
- Added an
offset
property to the parser to complementline
+col
npm install node-xml-lite2
var xml = require('node-xml-lite2');
xml.parseFile('~/test.xml', function(err, root) {
// ...
});
var xml = require('node-xml-lite2');
var root = xml.parseFileSync('~/test.xml');
var xml = require('node-xml-lite2');
xml.parseString('<xml>hello</xml>');
var xml = require('node-xml-lite2');
xml.parseBuffer(Buffer.from('<xml>hello</xml>', 'utf8'));
var xml = require('node-xml-lite2');
var parser = new xml.XmlParser();
var buffer = fs.readFileSync('~/large-file.xml');
parser.parseBuffer(buffer, buffer.length, function(state, name, value) {
switch (state) {
case xml.xtOpen:
console.log('opening:', name);
break;
case xml.xtClose:
console.log('closing:', name);
break;
case xml.xtAttribute:
console.log('attribute:', name + '=' + value);
break;
case xml.xtCData:
console.log('CDATA:', name);
break;
case xml.xtComment:
console.log('comment:', name);
break;
}
return true;
});