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.
Installation
Section titled “Installation”Install StAX-XML using your preferred package manager:
# npmnpm install stax-xml
# yarnyarn add stax-xml
# pnpmpnpm add stax-xml
# bunbun add stax-xml
# denodeno add npm:stax-xmlESM-only package: StAX-XML is published as ESM-only. Use import { ... } from 'stax-xml'; require('stax-xml') is not supported.
Platform Compatibility
Section titled “Platform Compatibility”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.
Core Concepts
Section titled “Core Concepts”StAX-XML provides two main parsing approaches:
Asynchronous Parsing (EventReader)
Section titled “Asynchronous Parsing (EventReader)”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}Synchronous Parsing (EventReaderSync)
Section titled “Synchronous Parsing (EventReaderSync)”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.
Next Steps
Section titled “Next Steps”- Quick Start Guide - Jump right in with practical examples
- Examples - See real-world usage patterns