Client-side XML validation in JavaScript


Emscripten comes with its own SDK, which bundles the specific versions of clang and node that it needs.

Install the Emscripten SDK and follow the instructions for setting it up.

Run ./ to set the PATH variable (you need to do this each time you want to use Emscripten).


xml.js is an Emscripten port of libxml2’s xmllint command, making it usable in a web browser.

Clone xml.js (and set up the submodules, if not done automatically).

Run npm install to install gulp.

Compile xmllint.js:

gulp clean
gulp libxml2 # compile libxml2
gulp compile # compile xmllint.js

Start a web server in the xml.js directory and open test/test.html to test it.

Importing multiple schema files

I’ve made a fork of xml.js which a) allows all the command-line arguments to be specified, so can be used for validating against a DTD rather than an XML schema, and b) allows a list of files to be specified, which are imported into the pseudo-filespace so that xmllint can access them. This makes running xmllint in the browser much more like running xmllint on the command line.

There is one caveat, which is that this version of xmllint still seems to try to fetch the DTD from the URL in the XML’s doctype declaration rather than that specified with the --dtdvalid argument, so the doctype needs to be edited to match the local file path to the DTD.