I wrote a DOM-based XML DTD Validator in ECMAScript. It cannot parse
DTDs, but given a DTD in a custom format, it will validate an element or
an entire document against that DTD. It comes with pre-defined DTDs for
XHTML 1.0 Strict, XHTML 1.0 Transitional, and XHTML 1.1. A demo is
It should work with HTML and XHTML documents; for XHTML documents, if
the browser ensures that the document is well-formed, this Validator is
as powerful (or limited) as the W3C Markup Validator with the following
caveat: attributes of types ID/IDREF/NMTOKEN/NMTOKENS are not checked
for proper syntax; this is simply because I did not bother writing the
regular expressions for these types.
While the code is not particularily optimized, on my computer the SMIL
2.0 specification's single-file version (~ 2.00 MB) is validated in 8s
by Opera 9, in 20s by Firefox trunk, and in ~ 100s by IE6, which is a
bit funny considering IE6 loads the document faster by some orders of
You can use this Validator e.g. to validate user comments if you allow
XHTML code somewhere, your own code, e.g. to conditionally display a
"valid" / "invalid" icon on your homepage for improved quality testing,
or you can modify the pre-defined DTDs to provide better validation as
the Markup Validator.
Converting DTDs into the format required by this tool is rather simple,
but my tools to do that are too crude to publish. If you would like to
use the Validator with any DTD not provided inline, please let me know
and I might consider converting it, if possible.
The code is huge unless gzip-compressed as I've done it above. The
compressed version is currently 9999 bytes. If you use only e.g. the
XHTML 1.0 Strict DTD and use one of the common compactor tools to
strip comments and such, and then compress it again, it is possible
to reduce the size to about 3.5 KB.
I do not intend to continue development of this tool, if you like to
take it over, please let me know.