Neanderthals Programming Machines
Miss any of our Open RFC calls?Watch the recordings here! »

node-xml-lite2

0.1.2 • Public • Published

node-xml-lite2

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.

Differences from node-xml-lite

  • Removed all SAXParse* API variants until I have time to rewrite them into a parseStream API
  • Exported the raw XmlParser class to allow for custom, lightweight parsing jobs (somewhat making up for the removal of the SAXParse* APIs)
  • Added TypeScript definition file
  • Added an offset property to the parser to complement line + col

Installation

npm install node-xml-lite2

Sample usage

Parse a file

var xml = require('node-xml-lite2');
xml.parseFile('~/test.xml', function(err, root) {
  // ...
});

Parse a file synchronously

var xml = require('node-xml-lite2');
var root = xml.parseFileSync('~/test.xml');

Parse a string

var xml = require('node-xml-lite2');
xml.parseString('<xml>hello</xml>');

Parse a buffer

var xml = require('node-xml-lite2');
xml.parseBuffer(Buffer.from('<xml>hello</xml>', 'utf8'));

Advanced usage

Custom parsing

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;
});

Keywords

Install

npm i node-xml-lite2

DownloadsWeekly Downloads

2

Version

0.1.2

License

none

Unpacked Size

53.4 kB

Total Files

7

Last publish

Collaborators

  • avatar