oxml-wasm 0.0.3

WebAssembly bindings for oxml: XML parsing and XPath in the browser
Documentation

Why this is possible

libxml-based crates cannot target WebAssembly without a libxml2 toolchain, which is most of the reason a browser-side XPath has not been practical in Rust. Being pure Rust with no C dependency is what makes these bindings work at all.

Build

wasm-pack build --target web

Usage

import init, { parse, isWellFormed } from "./pkg/oxml_wasm.js";

await init();

const doc = parse(`
  <library>
    <book lang="en"><title>Dune</title></book>
    <book lang="fr"><title>Germinal</title></book>
  </library>
`);

doc.queryText("//book[@lang='en']/title");  // ["Dune"]
doc.queryValue("count(//book)");             // "2"
doc.queryCount("//book");                    // 2
doc.rootName;                                // "library"

isWellFormed("<a></b>");                     // false

API

Export What it does
parse(source) Parse a document; throws with line and column if malformed
isWellFormed(source) Check without keeping the tree
doc.queryText(expr) Matched nodes' text, as an array
doc.queryValue(expr) The expression's value as a string
doc.queryCount(expr) How many nodes matched
doc.rootName The root element's name
doc.size Node count

Design

The surface is deliberately small. JavaScript already has DOMParser; what it does not have is a fast, dependency-free XPath that behaves identically to the server-side one.

Queries return text rather than node handles. A node handle is only meaningful against the document that issued it, and passing an opaque integer across the WASM boundary invites exactly the misuse the Rust API's type system prevents.

The oxml suite

Every member ships the same version number, so there is never a compatibility table to consult. Versions advance in 0.0.1 steps along the 0.0.x line; 0.1.0 follows 0.0.999.

Crate What it is
oxml Core — parser, tree, XPath 1.0
oxml-cli Command-line querying and validation
oxml-lsp Diagnostics for editors
oxml-mcp Model Context Protocol server
oxml-wasm WebAssembly bindings
xmlschema XSD validation

Contributing

See CONTRIBUTING.md. By participating you agree to the Code of Conduct.

License

Licensed under either of

at your option.