# libxml2-wasm

> WebAssembly-based libxml2 javascript wrapper

Latest version **0.7.2** (published 2026-09-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install libxml2-wasm
pnpm add libxml2-wasm
yarn add libxml2-wasm
bun add libxml2-wasm
```

## Health

**Score 60/100 (C)** — status: active.

Positive: no vulnerabilities; has provenance; recently updated; high maintenance score.

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

## Facts

| | |
|---|---|
| Version | 0.7.2 |
| Published | 2026-09-07 |
| First published | 2023-10-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=18 |
| Dependencies | 0 |
| Unpacked size | 1.2 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 53 |
| Author | James Lan |
| Maintainers | jameslan |
| Keywords | xml, xml parser, libxml, WebAssembly |

## Links

- npm: https://www.npmjs.com/package/libxml2-wasm
- Repository: https://github.com/jameslan/libxml2-wasm
- Homepage: https://jameslan.github.io/libxml2-wasm/
- Issues: https://github.com/jameslan/libxml2-wasm/issues
- npm.io page: https://npm.io/package/libxml2-wasm

## 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

- 0.7.2 (latest) — 2026-09-07
- 0.7.1 — 2026-03-12
- 0.7.0 — 2026-03-05
- 0.6.0 — 2025-08-09
- 0.5.0 — 2025-01-02
- 0.4.1 — 2024-10-17
- 0.4.0 — 2024-09-16
- 0.3.1 — 2024-06-18
- 0.3.0 — 2024-03-05
- 0.2.0 — 2023-12-27
- 0.1.0 — 2023-11-06
- 0.0.6 — 2023-10-15
- 0.0.5 — 2023-10-12
- 0.0.4 — 2023-10-11
- 0.0.3 — 2023-10-09
- … 1 more at https://npm.io/package/libxml2-wasm/versions

## README

# libxml2-wasm

[![CI Build on master](https://github.com/jameslan/libxml2-wasm/actions/workflows/build.yml/badge.svg)](https://github.com/jameslan/libxml2-wasm/actions/workflows/build.yml)
[![npm](https://img.shields.io/npm/v/libxml2-wasm?logo=npm)](https://www.npmjs.com/package/libxml2-wasm)

# Why Choose Another XML Library?

When comparing the previous two main approaches —
pure JavaScript implementation and traditional C implementation binding —
WebAssembly offers a unique combination of advantages.
It provides excellent performance while maintaining the best compatibility with modern JavaScript runtimes.

|                               | Javascript Implementation |       Traditional C Binding        |    WebAssembly    |
|-------------------------------|:-------------------------:|:----------------------------------:|:-----------------:|
| Parsing Speed                 |        Average[^1]        |                Fast                |       Fast        |
| C/C++ Toolchain at Runtime    |       Not required        |            Required[^2]            |   Not Required    |
| Prebuilt Binaries             |            N/A            |  One for each OS / Runtime / Arch  | Universal for all |
| Prebuilt Binary Compatibility |            N/A            | May be broken across libc versions |     Very Good     |
| Browser Compatibility         |            Yes            |                 No                 |        Yes        |

## Documentation

https://jameslan.github.io/libxml2-wasm/index.html

# Supported Environments

Due to the usage of WebAssembly, ES module and [top level await](https://caniuse.com/?search=top%20level%20await) etc,
this library requires the minimum version of the following environments,

| Environment |Version|
|:-----------:|:---:|
|   Node.js   |v18+|
|   Chrome    |V89+|
|    Edge     |V89+|
|   Safari    |v15+|

# Features
- Parsing & Querying
- Validating
- Modifying
- Serializing
- XInclude and XSD include/import (experimental)

## Getting started

Install `libxml2-wasm` package:

```shell
npm i libxml2-wasm
```

`libxml2-wasm` is an ES module,
the import process differs between ES modules and CommonJS modules.

### From ES Module

```js
import fs from 'node:fs';
import { XmlDocument } from 'libxml2-wasm';
const doc1 = XmlDocument.fromString('<note><to>Tove</to></note>');
const doc2 = XmlDocument.fromBuffer(fs.readFileSync('doc.xml'));
doc1.dispose();
doc2.dispose();
```

### From CommonJS

```js
const fs = require('node:fs');
import('libxml2-wasm').then(({ XmlDocument }) => {
    const doc1 = XmlDocument.fromString('<note><to>Tove</to></note>');
    const doc2 = XmlDocument.fromBuffer(fs.readFileSync('doc.xml'));
    doc1.dispose();
    doc2.dispose();
});
```

**IMPORTANT**: `dispose()` is required to avoid memory leak.

For more detail, see the [Doc](https://jameslan.github.io/libxml2-wasm/index.html).

# Contributing

Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for detailed information.

---

[^1]: The performance of different XML libraries can vary significantly.
For more information, refer to the [benchmark](docs/performance.md) provided.
[^2]: The requirement of a C/C++ toolchain at runtime can be waived if prebuilt binaries are available.

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