How to Define Validation in XML

This article describe how to define validation in XML.
  • 1995

DTD  Validation

Validation in XML file against a DTD need a XML file and its DTD document. first of all made a DTD file. This DTD file defines all elements  to keep in the XML file. Then we parse the XML file using the parser() method and generate a document  object type.

Validating With the XML Parser

If we first time try to open a xml document, XML parser may be generate a error by accessing the parser object. We  might  retrieve the error code, the error text, or the line that caused the error.

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

Example:

var xmlDocument = new ActiveXObject("MY.XMLDOM");
xmlDocument.async="false";
xmlDocument.validateOnParse="true";
xmlDocucument.load("note_dtd_error.xml");

document.write("<br /> Thisis Error Code: ");
document.write(xmlDocument.parseError.errorCode);
document.write("<br /> This id Error Reason: ");
document.write(xmlDocument.parseError.reason);
document.write("<br />Error Line number: ");
document.write(xmlDoc.parseError.line);

 

Turn Validation Off

var xmlDocument = new ActiveXObject("My.XMLDOM");
xmlDocument.async="false";
xmlDocument.validateOnParse="false";
xmlDocument.load("note_dtd_error.xml");

document.write("<br /> this is Error Code: ");
document.write(xmlDocument.parseError.errorCode);
document.write("<br /> This is Error Reason: ");
document.write(xmlDocument.parseError.reason);
document.write("<br />Error Line number: ");
document.write(xmlDocument.parseError.line);

 

further Readings

You may also want to read these related articles :

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2019 DotNetHeaven. All rights reserved.