<html>
<head>
<title>Validating XML against a schema</title>
<script language="JavaScript">
function validate() {
var xmlDoc = new ActiveXObject("MSXML2.DOMDocument.4.0");
var schemaCache = new ActiveXObject("MSXML2.XMLSchemaCache.4.0");
xmlDoc.async = false;
xmlDoc.resolveExternals = false;
xmlDoc.validateOnParse = false;
schemaCache.add("x-schema:bla", "path/to/schema.xsd");
xmlDoc.schemas = schemaCache;
xmlDoc.validateOnParse = true;
if (xmlDoc.loadXML(document.f.xml.value)) {
document.write("xml is valid.");
}
else {
if (xmlDoc.parseError.errorCode != 0) {
document.write("Error: "+xmlDoc.parseError.reason);
}
}
}
</script>
</head>
<body>
<h1>Validating XML Schemas </h1>
<form name='f'>
<b>XML:</b><br>
<textarea name='xml' style='width=500px;height=300px'></textarea>
<br><input type='button' value='Traverse XML' onClick='return validate();'>
</form>
</html>