@simple-api-stream/xml
v1.1.0
Published
Streaming XML (SAX) parser and serializer built on the Web Streams API
Downloads
425
Maintainers
Readme
@simple-api-stream/xml
Streaming XML (SAX = Simple API for XML) parser and serializer built on the Web Streams API.
Installation
npm install @simple-api-stream/xmlRequires Node.js >= 24 or any runtime supporting Web Streams and async iteration of ReadableStream.
Features
| Class | Stream type | Input | Output |
|-------|-------------|-------|--------|
| XMLTextToSAXTransformStream | TransformStream | XML text (string chunks) | SAXEventInterface objects |
| XMLTextToSAXEventWritableStream | WritableStream | XML text (string chunks) | Calls a SAXHandler |
| SAXToXMLTextTransformStream | TransformStream | SAX events | XML text |
| ResolveToSAXReadableStream | ReadableStream | Method calls (SAXResolver) | SAX events |
Usage
import { XMLTextToSAXTransformStream } from "@simple-api-stream/xml";
const events = xmlTextStream.pipeThrough(new XMLTextToSAXTransformStream());
for await (const event of events) {
if (event.name === "startElement")
console.log(event.tagName, event.attrs);
}SAX Events
| name | Extra fields |
|--------|--------------|
| startDocument | kind: "xml" |
| endDocument | – |
| startElement | tagName, attrs: Record<string, string>, selfClosing: boolean |
| endElement | tagName |
| text | text (numeric references and XML/HTML5 named entities are unescaped) |
| cdata | cdata |
| comment | comment (preserved verbatim without entity unescaping) |
| doctype | root, dtdType?: "PUBLIC" \| "SYSTEM", identifier?, uri?, declarations?: string[] |
| processingInstruction | target, data; <?xml …?> additionally has version, encoding, standalone, and <?xml-stylesheet …?> has type, href |
For full options, error classes, and usage examples, see the root README.
