Performs run-time validation on the currently loaded document using the currently loaded DTD, schema, or schema collection. This method only validates fully loaded documents (readyState == 4).
objXMLDOMDocument.validate
A ParseError object indicating exactly what error occurred, if any.
The validate method returns an IXMLDOMParseError object that is independent of the object returned by the parseError property on a document. Only the errorCode and reason properties of the returned object are set.
Unlike load, validate will fail if there is no DTD/schema applied to the document element. Therefore, validate will not be able tell you whether the document is just well-formed.
The validate method does not parse new schemas but may import a schema from a SchemaCache associated with the document through the schemas property. If there is no schema for a given namespace, the elements in that namespace will not be validated.
The following JScript example shows how to validate at run time:
var xmldoc = new ActiveXObject("Msxml2.DOMDocument"); xmldoc.async = false // This will validate on load because validateOnParse is set to true // by default. xmldoc.load("http://server/myData.xml"); // You make a change to an attribute: xmldoc.documentElement.setAttribute("a", "123"); // Now you want to verify your document is still valid: var err = xmldoc.validate(); if (err.errorCode == 0) { alert("Document is valid"); } else { alert("Validation error:" + err.reason); }
Applies To: XMLDOMDocument2 Object