--- title: "@std/xml" description: "XML parsing and serialization for Deno." jsr: jsr:@std/xml pkg: xml version: 0.1.0 generated: true stability: stable --- ## Overview
XML parsing and serialization for Deno.
This module implements a non-validating XML 1.0 parser based on the W3C XML 1.0 (Fifth Edition) specification.
Two parsing APIs are provided for different use cases:
| API | Use Case | Output |
|---|---|---|
parse |
Parse a complete XML string | Document tree |
parseXmlStream |
Streaming with maximum throughput | Direct callbacks |
For maximum throughput when processing large files:
```js import { parseXmlStream } from "@std/xml"; const response = await fetch("https://example.com/feed.xml"); const textStream = response.body!.pipeThrough(new TextDecoderStream()); let itemCount = 0; await parseXmlStream(textStream, { onStartElement(name) { if (name === "item") itemCount++; }, }); console.log(`Found ${itemCount} items`); ```For convenience with fetch responses:
```js import { parseXmlStreamFromBytes } from "@std/xml"; const response = await fetch("https://example.com/feed.xml"); await parseXmlStreamFromBytes(response.body!, { onStartElement(name) { console.log(`Element: ${name}`); }, }); ```Both parsers support optional position tracking (line, column, offset) for debugging and error reporting:
DOM parser (parse): Position tracking is enabled by default
to provide detailed error messages. Disable with { trackPosition: false }
for a performance boost when parsing trusted XML.
Streaming parser (parseXmlStream): Position tracking is
disabled by default for optimal streaming performance. Enable with
{ trackPosition: true } when you need position info.