<!doctype html>
<meta charset="utf-8" />
<title>oxml-wasm in a browser</title>
<style>
body { font: 16px/1.5 system-ui, sans-serif; max-width: 46rem; margin: 2rem auto; padding: 0 1rem; }
textarea { width: 100%; height: 9rem; font-family: ui-monospace, monospace; }
input { width: 100%; font-family: ui-monospace, monospace; padding: .4rem; }
pre { background: #f4f4f5; padding: .75rem; overflow-x: auto; }
.bad { color: #b91c1c; }
</style>
<h1>oxml-wasm</h1>
<p>XPath 1.0 in the browser, with no C toolchain.</p>
<label>Document<textarea id="xml">
<catalogue>
<book lang="en"><title>Dune</title><price>9.99</price></book>
<book lang="fr"><title>Germinal</title><price>7.50</price></book>
</catalogue></textarea></label>
<label>Expression<input id="expr" value="//title" /></label>
<pre id="out">…</pre>
<script type="module">
import init, { parse } from "../../pkg/oxml_wasm.js";
await init();
const xml = document.querySelector("#xml");
const expr = document.querySelector("#expr");
const out = document.querySelector("#out");
function run() {
let doc;
try {
doc = parse(xml.value);
} catch (e) {
out.className = "bad";
out.textContent = e.message;
return;
}
try {
out.className = "";
const nodes = doc.queryText(expr.value);
out.textContent =
`${doc.queryCount(expr.value)} node(s)\n` +
`value: ${doc.queryValue(expr.value)}\n\n` +
nodes.join("\n");
} catch (e) {
out.className = "bad";
out.textContent = e.message;
} finally {
doc.free();
}
}
xml.addEventListener("input", run);
expr.addEventListener("input", run);
run();
</script>