DTD validation
Use Internet Explorer to validate your XML against a DTD.
Validation through XML parser
When you try to open an XML document, the XML parser may generate an error. By accessing the parseError object, you can retrieve the exact code, text, and even line that caused the error.
Note: The load() method is for files, while the loadXML() method is for strings.
Instance
<html> <body> <h3> This demonstrates a parser error: </h3> <script> var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async="false"; xmlDoc.validateOnParse="true"; xmlDoc.load("note_dtd_error.xml"); document.write("<br>Error Code: "); document.write(xmlDoc.parseError.errorCode); document.write("<br>Error Reason: "); document.write(xmlDoc.parseError.reason); document.write("<br>Error Line: "); document.write(xmlDoc.parseError.line); </script> </body> </html>
Run Instance»
Click the "Run Instance" button to view the online instance
View xml file
Turn off validation
You can turn off validation by setting validateOnParse of the XML parser to "false".
Instance
<html> <body> <script> var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async="false"; xmlDoc.validateOnParse="false"; xmlDoc.load("note_dtd_error.xml"); document.write("<br>Error Code: "); document.write(xmlDoc.parseError.errorCode); document.write("<br>Error Reason: "); document.write(xmlDoc.parseError.reason); document.write("<br>Error Line: "); document.write(xmlDoc.parseError.line); </script> </body> </html>
Run Instance»
Click the "Run Instance" button to view the online instance
Universal XML Validator
To help you validate XML files, we have created this link so you can validate any XML file.
parseError Object
You can read more about the parseError object in our XML DOM Tutorial.