Skip to content

Getting Started

StAX-XML is a high-performance, pull-based XML parser for JavaScript/TypeScript that works across JavaScript runtimes with a pure JavaScript parser core.

Install StAX-XML using your preferred package manager:

Terminal window
# npm
npm install stax-xml
# yarn
yarn add stax-xml
# pnpm
pnpm add stax-xml
# bun
bun add stax-xml
# deno
deno add npm:stax-xml

ESM-only package: StAX-XML is published as ESM-only. Use import { ... } from 'stax-xml'; require('stax-xml') is not supported.

StAX-XML keeps a Web Standard API baseline, making it compatible with:

  • Node.js (v20.19+)
  • Bun (any version)
  • Deno (any version)
  • Web Browsers (modern browsers)
  • Edge Runtime (Vercel, Cloudflare Workers, etc.)

Browser parsing uses the same JavaScript parser path as server runtimes, so deployments do not need binary parser artifacts.

StAX-XML provides two main parsing approaches:

For memory-efficient processing of large XML files using streams:

import { EventReader } from 'stax-xml';
const reader = new EventReader(readableStream);
for await (const event of reader) {
// Process XML events
}

For high-performance parsing of smaller, in-memory XML strings:

import { EventReaderSync } from 'stax-xml';
const reader = new EventReaderSync(xmlString);
for (const event of reader) {
// Process XML events
}

For large byte-oriented workloads, use StreamReader or StreamReaderSync and consume each StreamBatch with eventCount plus index accessors.