node-expat
NodeJS binding for fast XML parsing.
Last updated 11 years ago by lloydwatkin .
· Repository · Original npm · Tarball · package.json
$ npm install node-expat 
SYNC missed versions from official npm registry.

node-expat

build status js-standard-style

Motivation

You use Node.js for speed? You process XML streams? Then you want the fastest XML parser: libexpat!

Install

npm install node-expat

Usage

Important events emitted by a parser:

(function () {
  "use strict";

  var expat = require('node-expat')
  var parser = new expat.Parser('UTF-8')

  parser.on('startElement', function (name, attrs) {
    console.log(name, attrs)
  })

  parser.on('endElement', function (name) {
    console.log(name)
  })

  parser.on('text', function (text) {
    console.log(text)
  })

  parser.on('error', function (error) {
    console.error(error)
  })

  parser.write('<html><head><title>Hello World</title></head><body><p>Foobar</p></body></html>')

}())

API

  • #on('startElement' function (name, attrs) {})
  • #on('endElement' function (name) {})
  • #on('text' function (text) {})
  • #on('processingInstruction', function (target, data) {})
  • #on('comment', function (s) {})
  • #on('xmlDecl', function (version, encoding, standalone) {})
  • #on('startCdata', function () {})
  • #on('endCdata', function () {})
  • #on('entityDecl', function (entityName, isParameterEntity, value, base, systemId, publicId, notationName) {})
  • #on('error', function (e) {})
  • #stop() pauses
  • #resume() resumes

Error handling

We don't emit an error event because libexpat doesn't use a callback either. Instead, check that parse() returns true. A descriptive string can be obtained via getError() to provide user feedback.

Alternatively, use the Parser like a node Stream. write() will emit error events.

Namespace handling

A word about special parsing of xmlns: this is not necessary in a bare SAX parser like this, given that the DOM replacement you are using (if any) is not relevant to the parser.

Benchmark

npm run benchmark

module ops/sec native XML compliant stream
sax-js 99,412
node-xml 130,631
libxmljs 276,136
node-expat 322,769

Higher is better.

Testing

npm install -g standard
npm test

Windows

If you fail to install node-expat as a dependency of node-xmpp, please update node-xmpp as it doesn't use node-expat anymore.

Dependencies for node-gyp https://github.com/TooTallNate/node-gyp#installation

See https://github.com/astro/node-expat/issues/78 if you are getting errors about not finding nan.h.

expat.vcproj

VCBUILD : error : project file 'node-expat\build\deps\libexpat\expat.vcproj' was not found or not a valid proj
ect file. [C:\Users\admin\AppData\Roaming\npm\node_modules\node-expat\build\bin
ding.sln]

Install Visual Studio C++ 2012 and run npm with the --msvs_version=2012 flag.

Current Tags

  • 2.4.1                                ...           latest (8 months ago)

48 Versions

  • 2.4.1                                ...           8 months ago
  • 2.4.0                                ...           4 years ago
  • 2.3.18                                ...           5 years ago
  • 2.3.17                                ...           6 years ago
  • 2.3.16                                ...           7 years ago
  • 2.3.15                                ...           8 years ago
  • 2.3.14                                ...           8 years ago
  • 2.3.13                                ...           9 years ago
  • 2.3.12                                ...           9 years ago
  • 2.3.11                                ...           9 years ago
  • 2.3.10                                ...           9 years ago
  • 2.3.9                                ...           9 years ago
  • 2.3.8                                ...           10 years ago
  • 2.3.7                                ...           10 years ago
  • 2.3.6                                ...           10 years ago
  • 2.3.5                                ...           10 years ago
  • 2.3.4                                ...           10 years ago
  • 2.3.3                                ...           10 years ago
  • 2.3.2                                ...           10 years ago
  • 2.3.1                                ...           10 years ago
  • 2.3.0                                ...           10 years ago
  • 2.2.0                                ...           11 years ago
  • 2.1.4                                ...           11 years ago
  • 2.1.3                                ...           11 years ago
  • 2.1.2                                ...           11 years ago
  • 2.1.1                                ...           11 years ago
  • 2.1.0                                ...           11 years ago
  • 2.0.0                                ...           12 years ago
  • 1.6.1                                ...           12 years ago
  • 1.6.0                                ...           12 years ago
  • 1.5.0                                ...           13 years ago
  • 1.4.5                                ...           13 years ago
  • 1.4.4                                ...           13 years ago
  • 1.4.3                                ...           13 years ago
  • 1.4.2                                ...           13 years ago
  • 1.4.1                                ...           13 years ago
  • 1.4.0                                ...           13 years ago
  • 1.3.2                                ...           13 years ago
  • 1.3.1                                ...           13 years ago
  • 1.3.0                                ...           14 years ago
  • 1.2.0                                ...           14 years ago
  • 1.1.1                                ...           14 years ago
  • 1.1.0                                ...           14 years ago
  • 1.0.1                                ...           14 years ago
  • 1.0.0                                ...           14 years ago
  • 0.0.6                                ...           14 years ago
  • 0.0.5                                ...           14 years ago
  • 0.0.4                                ...           14 years ago
Maintainers (2)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (1)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE