Page 1 of 1

Javascript Validation Problem

Posted: Thu May 07, 2009 1:47 am
by s2009
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:

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>
 
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!!

Re: Error!

Posted: Thu May 07, 2009 11:54 am
by Benjamin
Forum Rules 1 1.1 2 wrote: Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.
:arrow: Moved to Javascript