npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-expat

v2.4.1

Published

NodeJS binding for fast XML parsing.

Downloads

531,528

Readme

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.