Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

DTD Validation

DTD Validation


With Internet Explorer you can validate your XML against a DTD.


Validating with an XML parser

When you try to open an XML document, the XML parser may produce an error. By accessing the parseError object you can retrieve the exact error code, text and even the line where it occurred.

Note: The load() method is used for files, while the loadXML() method is used for strings.

Example

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");

xmlDoc.async="false";

xmlDoc.validateOnParse="true";

xmlDoc.load("note_dtd_error.xml");

document.write("
Error Code: ");

document.write(xmlDoc.parseError.errorCode);

document.write("
Error Reason: ");

document.write(xmlDoc.parseError.reason);

document.write("
Error Line: ");

document.write(xmlDoc.parseError.line);

Try it »

View the XML file


Turning off validation

By setting the XML parser's validateOnParse to "false", you can turn off validation.

Example

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");

xmlDoc.async="false";

xmlDoc.validateOnParse="false";

xmlDoc.load("note_dtd_error.xml");

document.write("
Error Code: ");

document.write(xmlDoc.parseError.errorCode);

document.write("
Error Reason: ");

document.write(xmlDoc.parseError.reason);

document.write("
Error Line: ");

document.write(xmlDoc.parseError.line);

Try it »


A generic XML validator

To help you validate XML files, we created this linkso you can validate any XML file.


The parseError object

You can find it in ourXML DOM Tutorialfor more information about the parseError object.