
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
High-performance, pull-based XML parser for JavaScript/TypeScript with declarative converter API
A high-performance, pull-based XML parser for JavaScript/TypeScript inspired by Java's StAX (Streaming API for XML). It offers both fully asynchronous, stream-based parsing for large files and synchronous parsing for smaller, in-memory XML documents. Unlike traditional XML-to-JSON mappers, StAX-XML allows you to map XML data to any custom structure you desire while efficiently handling XML files through streaming or direct string processing.
# 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
Here are basic examples to get started. StAX-XML provides two parsing approaches:
The converter module provides a zod-style declarative API for parsing and writing XML:
import { x } from 'stax-xml/converter';
// Define schema with XPath
const bookSchema = x.object({
title: x.string().xpath('/book/title'),
author: x.string().xpath('/book/author'),
price: x.number().xpath('/book/price'),
tags: x.string().array().xpath('/book/tags/tag')
});
// Parse XML
const xml = `
<book>
<title>TypeScript Deep Dive</title>
<author>John Smith</author>
<price>29.99</price>
<tags>
<tag>programming</tag>
<tag>typescript</tag>
</tags>
</book>
`;
const result = await bookSchema.parse(xml);
// Result: { title: 'TypeScript Deep Dive', author: 'John Smith', price: 29.99, tags: ['programming', 'typescript'] }
// Write XML back
const newXml = await bookSchema.write(result, { rootElement: 'book' });
Key features of the Converter API:
.optional().transform()import { StaxXmlParser, XmlEventType } from 'stax-xml';
const xmlContent = '<root><item>Hello</item></root>';
const stream = new ReadableStream({
start(controller) {
controller.enqueue(new TextEncoder().encode(xmlContent));
controller.close();
}
});
async function parseXml() {
const parser = new StaxXmlParser(stream);
for await (const event of parser) {
console.log(event);
}
}
parseXml();
import { StaxXmlParserSync, XmlEventType } from 'stax-xml';
const xmlContent = '<data><value>123</value></data>';
const parser = new StaxXmlParserSync(xmlContent);
for (const event of parser) {
console.log(event);
}
For detailed API documentation:
StAX-XML uses only Web Standard APIs, making it compatible with:
bun test
Disclaimer: These benchmarks were performed on a specific system (cpu: 13th Gen Intel(R) Core(TM) i5-13600K, runtime: node 22.17.0 (x64-win32)) and may vary on different hardware and environments.
large.xml (97MB) parsing
| Benchmark | avg (min … max) | p75 / p99 | Memory (avg) |
|---|---|---|---|
| stax-xml to object | 4.36 s/iter | 4.42 s | 2.66 mb |
| stax-xml consume | 3.61 s/iter | 3.65 s | 3.13 mb |
| xml2js | 6.00 s/iter | 6.00 s | 1.80 mb |
| fast-xml-parser | 4.25 s/iter | 4.26 s | 151.81 mb |
| txml | 1.05 s/iter | 1.06 s | 179.81 mb |
midsize.xml (13MB) parsing
| Benchmark | avg (min … max) | p75 / p99 | Memory (avg) |
|---|---|---|---|
| stax-xml to object | 492.06 ms/iter | 493.28 ms | 326.28 kb |
| stax-xml consume | 469.66 ms/iter | 471.54 ms | 174.51 kb |
| xml2js | 163.26 µs/iter | 161.20 µs | 89.89 kb |
| fast-xml-parser | 529.99 ms/iter | 531.12 ms | 1.92 mb |
| txml | 112.81 ms/iter | 113.26 ms | 1.00 mb |
complex.xml (2KB) parsing
| Benchmark | avg (min … max) | p75 / p99 | Memory (avg) |
|---|---|---|---|
| stax-xml to object | 85.79 µs/iter | 75.60 µs | 105.11 kb |
| stax-xml consume | 50.38 µs/iter | 49.43 µs | 271.12 b |
| xml2js | 147.45 µs/iter | 153.50 µs | 89.42 kb |
| fast-xml-parser | 101.11 µs/iter | 102.20 µs | 92.92 kb |
| txml | 9.40 µs/iter | 9.41 µs | 125.89 b |
books.xml (4KB) parsing
| Benchmark | avg (min … max) | p75 / p99 | Memory (avg) |
|---|---|---|---|
| stax-xml to object | 166.73 µs/iter | 156.20 µs | 221.40 kb |
| stax-xml consume | 176.45 µs/iter | 151.70 µs | 202.08 kb |
| xml2js | 259.90 µs/iter | 254.50 µs | 161.25 kb |
| fast-xml-parser | 239.57 µs/iter | 203.30 µs | 226.17 kb |
| txml | 19.18 µs/iter | 19.26 µs | 303.13 b |
Sources of sample XML files used in testing:
books.xml: Microsoft XML Document Examplessimple-namespace.xml: W3Schools XML Namespaces Guidetreebank_e.xml: University of Washington XML Data RepositoryMIT
Contributions are welcome! Please feel free to submit a Pull Request.
Java의 StAX(Streaming API for XML)에서 영감을 받은 고성능 pull 방식의 JavaScript/TypeScript XML 파서입니다. 대용량 파일을 위한 완전 비동기 스트림 기반 파싱과 작은 인메모리 XML 문서를 위한 동기 파싱을 모두 제공합니다. 기존의 XML-JSON 매퍼와 달리, StAX-XML을 사용하면 XML 데이터를 원하는 임의의 구조로 매핑할 수 있으며, 스트리밍 또는 직접 문자열 처리를 통해 XML 파일을 효율적으로 처리할 수 있습니다.
# 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
자세한 사용법, API 참조, 튜토리얼은 공식 문서를 참조하세요.
StAX-XML은 두 가지 파싱 방식을 제공합니다:
Converter 모듈은 XML 파싱 및 쓰기를 위한 Zod 스타일의 선언적 API를 제공합니다:
import { x } from 'stax-xml/converter';
// XPath를 사용한 스키마 정의
const bookSchema = x.object({
title: x.string().xpath('/book/title'),
author: x.string().xpath('/book/author'),
price: x.number().xpath('/book/price'),
tags: x.string().array().xpath('/book/tags/tag')
});
// XML 파싱
const xml = `
<book>
<title>TypeScript 딥다이브</title>
<author>홍길동</author>
<price>29.99</price>
<tags>
<tag>프로그래밍</tag>
<tag>타입스크립트</tag>
</tags>
</book>
`;
const result = await bookSchema.parse(xml);
// 결과: { title: 'TypeScript 딥다이브', author: '홍길동', price: 29.99, tags: ['프로그래밍', '타입스크립트'] }
// XML로 다시 쓰기
const newXml = await bookSchema.write(result, { rootElement: 'book' });
Converter API의 주요 기능:
.optional()로 누락된 요소 우아하게 처리.transform()으로 사용자 정의 변환 적용import { StaxXmlParser, XmlEventType } from 'stax-xml';
const xmlContent = '<root><item>안녕하세요</item></root>';
const stream = new ReadableStream({
start(controller) {
controller.enqueue(new TextEncoder().encode(xmlContent));
controller.close();
}
});
async function parseXml() {
const parser = new StaxXmlParser(stream);
for await (const event of parser) {
console.log(event);
}
}
parseXml();
import { StaxXmlParserSync, XmlEventType } from 'stax-xml';
const xmlContent = '<data><value>123</value></data>';
const parser = new StaxXmlParserSync(xmlContent);
for (const event of parser) {
console.log(event);
}
자세한 API 문서는 다음을 참조하세요:
StAX-XML은 웹 표준 API만을 사용하여 다음 환경에서 동작합니다:
테스트에 사용된 샘플 파일들의 출처:
XML 파일:
books.xml: Microsoft XML 문서 예제simple-namespace.xml: W3Schools XML 네임스페이스 가이드treebank_e.xml: University of Washington XML Data RepositoryJSON 파일:
MIT
기여를 환영합니다! Pull Request를 자유롭게 제출해 주세요.
FAQs
High-performance, pull-based XML parser for JavaScript/TypeScript with declarative converter API
We found that stax-xml demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.