Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

DTD validation


May 28, 2021 DTD


Table of contents


DTD verification

With DTD, you can validate your XML files, as discussed in this section.

Use Internet Explorer to validate your XML based on a DTD.


Validate with an XML parser

When you try to open an XML document, the XML parser can produce an error. By accessing the parseError object, you can get back the exact code, text, and even the line that caused the error.

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

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);

Try it out . . .

View the xml file


Turn off validation

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

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);

Try it out . . .



A common XML validator

To help you validate the XML file, we created this link so that you can validate any XML file.


ParseError object

You can read more about parseError objects in our XML DOM tutorial.

That's all about DTD validation XML, which can indicate that XML is "legitimate."