Javascript Validation Problem

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
s2009
Forum Newbie
Posts: 20
Joined: Thu Apr 30, 2009 1:20 am

Javascript Validation Problem

Post 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!!
Last edited by Benjamin on Thu May 07, 2009 11:56 am, edited 2 times in total.
Reason: Added [code=javascript] tags. Changed title from "Error!" to "Javascript Validation Problem"
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Error!

Post 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
Post Reply