Coder Social home page Coder Social logo

node-expat's Introduction

node-expat

Motivation

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

Speed

A stupid speed test is supplied in bench.js. We measure how many 25-byte elements a SAX parser can process:

  • node-xml (pure JavaScript): 23,000 el/s
  • libxmljs (libxml2 binding): 77,000 el/s
  • node-expat (libexpat binding, this): 113,000 el/s

These numbers were recorded on a Core 2 2400 MHz and may turn out to be bullshit, given my few node.js experience.

Instructions

Install dependencies:

  • Debian/Ubuntu: apt-get install libexpat1-dev
  • Centos/Red Hat: yum install expat-devel

Install node-expat:

npm i node-expat

Usage

Important events emitted by a parser:

  • startElement with name, attrs
  • endElement with name
  • text with string

There are more. Use test.js for reference.

It's possible to stop and resume the parser from within element handlers using the parsers stop() and resume() methods.

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.

Namespace handling

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

node-expat's People

Contributors

astro avatar sh1mmer avatar andreasbotsikas avatar c4milo avatar xzachtli avatar hammerdr avatar mazdermind avatar satyamshekhar avatar zerodivisi0n avatar dhruvbird avatar iein avatar mweibel avatar tootallnate avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.