Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including node-xml-lite with all npm packages installed. Try it out:

var nodeXmlLite = require("node-xml-lite")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

node-xml-lite v0.0.7

Pure javascript XML ANSI/Unicode SAX parser for Node.js


  • 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.


npm install node-xml-lite

Simple usage

Parse a file

xml = require("node-xml-lite");

xml.parseFile(filename, function(err, root){

Parse a file synchronously


Parse a string


Parse a buffer

xml.parseBuffer(new Buffer("<xml>hello</xml>"));

Advanced usage

parsing a file in SAX mode

  function(state, a, b) {
    switch (state) {
      case xml.xtOpen:
        // a is node name
      case xml.xtClose
      case xml.xtAttribute:
        // a is attribute name
        // b is attribute value
      case xml.xtText:
        // a is a text value
      case xml.xtCData:
        // a is a CDATA text value
      case xml.xtComment
        // a is a comment text value
    // tell the parser to continue
    return true;
    // parser done, check error

you can also use the sync function,

xml.SAXParseFileSync(filename, event)

providing your own data to SAX parser

var parser = new xml.XMLParser();
var ret = parser.parserBuffer(buffer, len, event);
if (ret === true) {
  // stopped by event result
} else
if (ret === false) {
  // there is a parsing error at:
  //   parser.line 
  //   parser.col
} else
if (ret === undefined) {
  // it is ok, continue ...

you can also parse a string

var ret = parser.parseString(str, event);
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free