Node.js XML libraries

  • sax-js: This is @izs’s pure javascript parser. I don’t really like the weird mixture of trying to accommodate Node.js streams, function events, and traditional event listeners, the strange error handling and pausing, but it’s solid if you can work around those quirks.

Many of the other pure JS XML libraries are layers on top of this.

  • node-xml2js: Converts XML into plain JS objects. Doesn’t abide by any of the XML conversion conventions, but has several options for specifying the conversion protocol. Not streaming.

  • node-expat: Fast, binds to the libexpat C library. Thus, builds can be messy. And it’s not pure JS.

  • libxmljs: Also fast, binds to libxml2, which is perhaps more standard than libexpat. Again requires an external library and thus might have some building issues, but besides that, it’s my favorite.

  • htmlparser2: Pure JS, oriented toward Node.js but can be browserify-ed. Supposedly fast. I haven’t used it. Does not depend on sax-js.

  • xmldom: Independent and very compliant DOM parser.