3.1.3 • Published 4 months ago

expat-wasm v3.1.3

Weekly downloads
2
License
MIT
Repository
github
Last release
4 months ago

expat-wasm

An XML parser based on expat.

The approach taken here was to compile to WASM with emscripten, and ship the WASM binary in the NPM package. This means you get a real, battle-tested XML parser, with 0 runtime dependencies.

To install:

npm install --save expat-wasm

To use:

import {XmlParser} from 'expat-wasm'

parser = new XmlParser()
parser.on('startElement', (name, attributes) => ...)
parser.parse('<foo/>')
parser.destroy()

You may enable expansion of external entity references, if you are very careful about not allowing access to unwanted files.

parser = new XmlParser({
  systemEntity(base, sysId, pubId) {
    // Check the new URL to ensure it is "safe", for your local definition of "safe".
    return {
      base: new URL(sysId, base).toString(),
      data: Buffer.from('<!ENTITY foo "bar" >'),
    }
  },
})

The systemEntity function MUST be synchronous, due to limitations of expat. If you need to read from the network asynchronously, one approach might be to call parser.stop(), wait until you've got all of the needed data, then try parsing again.

There are docs.

Requires nodejs 16 or higher, and works in a modern browser using WebPack. See the webpack-demo directory for simple WebPack example.

Note that expat currently only supports XML 1.0, edition 4.

See an online demo here.

Tests codecov

3.1.3

4 months ago

3.1.2

12 months ago

3.1.1

12 months ago

3.1.0

12 months ago

3.0.0

1 year ago

2.0.2

3 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago