I am trying to create a schema validation program using JavaScript.
I have used the following code to display whether there is any error:
Code: Select all
<script type = "text/javascript">
var transformedwindow;
var xmlDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.6.0");
xmlDoc.async=false;
xmlDoc.load(document.frmTransform.TxtXMLFileName.value);
var namespace=xmlDoc.documentElement.namespaceURI;
xmlDoc.validateOnParse=true;
var xsdschemacache=new ActiveXObject("Msxml2.XMLSchemaCache.6.0");
xsdschemacache.add(namespace,document.frmTransform.TxtXSDFileName.value);
xmlDoc.schemas=xsdschemacache;
xmlDoc.load(document.frmTransform.TxtXMLFileName.value);
var error=xmlDoc.parseError.errorCode;
transformedwindow=window.open('Transformed.html','_new','location=0,status = 1,toolbar =0,menubar=0,scrollbars
=0,directories=0,resizable=0,width=600,height=600');
if(error!="")
{
transformedwindow.document.write('<HTML><TITLE>Schema Validator</TITLE><BODY><P><b> Error Validating the
document</b></p><br>');
transformedwindow.document.write('<b>Error URL : </b><br>'+error.url+ '<br>');
transformedwindow.document.write('<b>Error Line : </b><br>' + error.line + '<br>');
transformedwindow.document.write('<b>Error LinePosition : </b> <br>' +error.linepos + '<br>');
transformedwindow.document.write('<b>Error Reson : </b><br/>' +error.reason + '<br>');
transformedwindow.document.write('</BODY></HTML>');
}
else
{
transformedwindow.document.write('<html><title>Schema Validator</title><body><b>No Error</b><br>');
transformedwindow.document.write('</body></html>');
}
}
</script>
So that I can get the desired results.
Please help me out.
Thanks in advance!!