xerces-wasm
v2.0.0
Published
Fast XML schema validator using Apache Xerces-C++ compiled to WebAssembly with in-memory XSD caching
Downloads
259
Maintainers
Readme
WASM XML Validator
XML validator using Apache Xerces-C++ compiled to WebAssembly. Features in-memory XSD caching for validation.
How it works
Xerces-C++ validation inherently splits into two main phases. The initial XSD parsing and compilation takes time, while the validation is fast.

The Validation Lifecycle
This shows how Xerces processes schemas versus how it validates XML files.
- One-Time Setup: Raw XSD files are scanned, traversed, and compiled into DFA (Deterministic Finite Automata) structures. This is stored as the XML Grammar Pool.
- Validation: The raw XML input is streamed through the pre-compiled Grammar Pool rules using a transient
SAXParserengine.
Our Architecture
We use WebAssembly linear memory to avoid re-parsing XSDs on every validation.

We separate the state:
- Persistent State: We compile the schema once and lock it inside an
XMLGrammarPoolin the WASM heap. Each workspace project maintains its own isolated pool. - Transient Engine: On every
validate()call, we create a new, disposableSAXParserengine. It attaches to the existing project grammar pool, validates the XML, and is destroyed.
Quick example
import { createProjectValidator } from "xerces-wasm";
// 1. Create a validator. This parses XSDs and caches the Grammar Pool in WASM memory.
const v = await createProjectValidator({
entry: "main.xsd",
files, // Map of { filename: xsdText }
});
// 2. Validate. It creates a transient SAXParser and uses the cached pool.
const result = await v.validate(`<log level="full"/>`);
console.log(result.valid); // true / false
// 3. Destroy to free the C++ allocations from WASM memory.
v.destroy();Setup & Build
Requires Git, Node.js, and an internet connection. Emscripten and Xerces-C are fetched automatically.
# Clone the repository
git clone --recurse-submodules https://github.com/harshanacz/xerces-wasm-validator
# Install Node dependencies
npm install
# Compile Xerces-C → wasm/xerces_validator.{js,wasm}
# (Downloads the Emscripten toolchain on first run)
npm run build:wasm
# Compile TypeScript → dist/
npm run build:ts
# Run the test suite
npm testLicense
MIT — see LICENSE.
Includes Apache Xerces-C++ (Apache-2.0) — see LICENSE-APACHE and NOTICE.
