Javascript Validation Problem
Posted: Thu May 07, 2009 1:47 am
Hi all
I am trying to create a schema validation program using JavaScript.
I have used the following code to display whether there is any error:
However If there is any error in the file it is not displaying any output. In short the If part in the If else construct is not executed can any one tell me what is the error? However, if there is no error it is opening a window and stating that "No Error!" Hence I think only the If Part is not executed. What changes should I make in the if construct to execute it.
So that I can get the desired results.
Please help me out.
Thanks in advance!!
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!!