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
Usage
import init from "./pkg/oxml_wasm.js";
await ;
const doc = ;
doc.; // ["Dune"]
doc.; // "2"
doc.; // 2
doc.; // "library"
; // 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
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.