# xml-toolkit

> A pure Node.js library for solving diverse XML-related application tasks with minimal resources and dependencies

Latest version **1.1.8** (published 2026-04-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install xml-toolkit
pnpm add xml-toolkit
yarn add xml-toolkit
bun add xml-toolkit
```

## Health

**Score 45/100 (D)** — status: active.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 1.1.8 |
| Published | 2026-04-26 |
| First published | 2021-11-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 150.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Dmitry Ovsyanko |
| Maintainers | do- |
| Keywords | xml, soap, xsd, wsdl, sax |

## Links

- npm: https://www.npmjs.com/package/xml-toolkit
- Repository: https://github.com/do-/node-xml-toolkit
- Homepage: https://do-.github.io/node-xml-toolkit/
- Issues: https://github.com/do-/node-xml-toolkit/issues
- npm.io page: https://npm.io/package/xml-toolkit

## Dependencies (2)

- [http-errors](https://npm.io/package/http-errors.md) ^2.0.0
- [string-escape-map](https://npm.io/package/string-escape-map.md) ^1.0.0

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.1.8 (latest) — 2026-04-26
- 1.1.7 — 2026-04-23
- 1.1.6 — 2026-04-05
- 1.1.5 — 2026-04-04
- 1.1.4 — 2026-03-18
- 1.1.3 — 2026-03-17
- 1.1.2 — 2026-03-16
- 1.1.1 — 2026-03-15
- 1.1.0 — 2026-03-14
- 1.0.61 — 2026-02-21
- 1.0.60 — 2025-10-28
- 1.0.59 — 2025-09-15
- 1.0.58 — 2025-07-16
- 1.0.57 — 2025-07-14
- 1.0.56 — 2025-07-09
- … 63 more at https://npm.io/package/xml-toolkit/versions

## README

![workflow](https://github.com/do-/node-xml-toolkit/actions/workflows/main.yml/badge.svg)
![Jest coverage](./badges/coverage-jest%20coverage.svg)
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/do-/node-xml-toolkit)
[![npm version](https://img.shields.io/npm/v/xml-toolkit.svg)](https://www.npmjs.com/package/xml-toolkit)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)

> A pure Node.js library for solving diverse XML-related application tasks with minimal resources and dependencies.

`node-xml-toolkit` handles XML parsing, marshalling, and SOAP integration — from streaming multi-gigabyte files to invoking SOAP 1.1 web services via WSDL.

---

## ✨ Features

- ♊ **Dual parsing modes**: Fast <ins>synchronous</ins> parser for small documents; <ins>streaming asynchronous</ins> parser for large files
- 🧠 **Memory-efficient**: Scan multi-GB XML files with limited buffer
- 🧬 **Schema support**: Validate and serialize objects using XML Schema (XSD)
- 🧼 **[SOAP](https://www.w3.org/TR/soap/) 1.1, 1.2 adapters**: Invoke web services directly from WSDL + plain JS objects
- 🖨️ **Flexible output**: Format, patch, or transform XML with configurable options
- 🎏 **Stream-ready**: Works with Node.js streams, async iterators, and event emitters

---

## 📦 Installation

```bash
npm install xml-toolkit
```

---

## 🚀 Quick Start

### Parse a Small XML File (Sync)

```js
const fs = require('fs');
const { XMLParser, XMLSchemata } = require('xml-toolkit');

const xml = fs.readFileSync('doc.xml');
const parser = new XMLParser(); // optionally: { xs: new XMLSchemata('schema.xsd') }
const document = parser.process(xml);

for (const element of document.detach().children) {
  console.log(element.attributes);
}
```

### Stream Large XML Files (Async)

```js
const { XMLReader, XMLNode } = require('xml-toolkit');

const records = new XMLReader({
  filterElements: 'Record',
  map: XMLNode.toObject({})
}).process(xmlSource);

// Use as async iterator
for await (const record of records) {
  // process each record
}

// Or pipe to another stream
// records.pipe(nextStream);
```

### Extract a Single Element

```js
const { XMLReader, XMLNode } = require('xml-toolkit');

const data = await new XMLReader({
  filterElements: 'MyElementName',
  map: XMLNode.toObject({})
}).process(xmlSource).findFirst();
```

### Format / Pretty-Print XML

```js
const { XMLParser } = require('xml-toolkit');

const formatted = new XMLParser()
  .process(fs.readFileSync('doc.xml'))
  .toString({
    space: '\t',        // indentation
    // EOL: '\n',        // line ending
    // encodeLineBreaks: false
  });
```

### Serialize Objects to XML (via XSD)

```js
const { XMLSchemata } = require('xml-toolkit');

const data = { ExportDebtRequestsResponse: { 'request-data': { /* ... */ } } };
const xs = new XMLSchemata('schema.xsd');
const xml = xs.stringify(data);
// → <ns0:ExportDebtRequestsResponse xmlns:ns0="urn:...">...
```

### Invoke a SOAP 1.1 Web Service

```js
const http = require('http');
const { SOAP11 } = require('xml-toolkit');

const soap = new SOAP11('service.wsdl');
const { method, headers, body } = soap.http({
  RequestElementNameOfTheirs: { amount: '0.01' }
});

const req = http.request(endpointURL, { method, headers });
req.write(body);
req.end();
```

---

## 🧭 Core API Overview

| Class / Export     | Purpose                                      | Mode       |
|--------------------|----------------------------------------------|------------|
| [`XMLParser`](https://do-.github.io/node-xml-toolkit/chapter_03.html)        | Synchronous full-document parsing            | Sync       |
| [`XMLReader`](https://do-.github.io/node-xml-toolkit/chapter_04.html)        | Streaming parser with filtering & mapping    | Async/Stream |
| [`XMLNode`](https://github.com/do-/node-xml-toolkit/wiki/XMLNode)          | DOM-like node representation + utilities     | Both       |
| `XMLSchemata`      | XSD-based [validation](https://do-.github.io/node-xml-toolkit/chapter_03.html#34-optional-validation-with-xmlschemata) & object→XML [serialization](https://do-.github.io/node-xml-toolkit/chapter_08.html) | Both    |
| [`SOAP`](https://do-.github.io/node-xml-toolkit/chapter_09.html#version-selection)             | SOAP adapter using WSDL                      | Sync setup |

---

## ⚠️ Limitations

- ❌ **No DTD support**: Entity declarations may cause parser errors
- 🧪 **XML Schema is "forever beta"**: Features like `xs:unique` are not implemented; validation coverage is partial
- 🔍 For production-grade validation, consider external tools like `xmllint` (used in the library's test suite)

---

## 💡 Motivation

Node.js lacks built-in XML tooling comparable to Java's [JAXB](https://javaee.github.io/jaxb-v2/)/[JAX-WS](https://javaee.github.io/metro-jax-ws/). While many pure-JS XML modules exist, `node-xml-toolkit` was created to deliver most necessary functions with:

- ✅ Minimal computing resources  
- ✅ Minimal application code  
- ✅ [Almost no](https://www.npmjs.com/package/xml-toolkit?activeTab=dependencies) external dependencies  

All in a pure JavaScript implementation.

---

## 📄 License

MIT © [do-](https://github.com/do-)

---

## 🔗 Links

- [GitHub Repository](https://github.com/do-/node-xml-toolkit)  
- [npm Package](https://www.npmjs.com/package/xml-toolkit)  
- [Documentation](https://do-.github.io/node-xml-toolkit)

---
_Source: https://npm.io/package/xml-toolkit · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
