Connecting Tech Pros Worldwide Forums | Help | Site Map

Using schema validation for update

Newbie
 
Join Date: Oct 2005
Posts: 2
#1: Oct 12 '05
I have a valid xml and schema.
I put them together in javascript and generate html.
Like this:
Expand|Select|Wrap|Line Numbers
  1. function initAdmin() {
  2.   var xslDoc
  3.   strFile="Simple.Config.xml"
  4.   strSchema="SimpleSchemaConfig.xsd";
  5.  
  6.   if (ValidateShema(strFile,strSchema)==true){
  7.       xmlDoc = new ActiveXObject('MSXML2.DOMDocument.4.0');
  8.       xmlDoc.async = false;
  9.  
  10.       xslDoc = new ActiveXObject('MSXML2.DOMDocument.4.0');
  11.       xslDoc.async = false;
  12.  
  13.       AppPath = xmlDoc.url;
  14.       xmlDoc.loadXML(xmlDoc.documentElement.transformNode(xslDoc));
  15.       xslDoc.load("FileTree.xsl");
  16.       folderTree.innerHTML = xmlDoc.documentElement.transformNode(xslDoc);  
  17. }
  18. }
  19.  
  20. function ValidateShema(strFile,strSchema){ 
  21.  
  22. try
  23. {
  24.        xmlDoc              = new ActiveXObject("MSXML2.DOMDocument.4.0");
  25.        schemaCache         = new ActiveXObject("MSXML2.XMLSchemaCache.4.0");
  26.  
  27.        xmlDoc.async            = false;
  28.        xmlDoc.resolveExternals = false;
  29.        xmlDoc.validateOnParse  = false;
  30.  
  31.        schemaCache.add("",strSchema);
  32.  
  33.        xmlDoc.schemas = schemaCache;
  34.        xmlDoc.validateOnParse = true;
  35.        if (xmlDoc.load(strFile)) {       
  36.          displayError("xml is valid.");
  37.          return true;
  38.        }
  39.        else {
  40.          if (xmlDoc.parseError.errorCode != 0) {
  41.            displayError("Validation failed on " + strFile + 
  42.                 "\nReason: " + xmlDoc.parseError.reason + 
  43.                 "\nSource: " + xmlDoc.parseError.srcText + 
  44.                 "\nLine: " + xmlDoc.parseError.line + "\n");
  45.                 isValid=0;
  46.                 return false;
  47.          }
  48.        }
  49. }
  50. catch(ex)
  51. {
  52.      alert("Error: " + ex.message)
  53. }
  54. }
Everything works just fine.

User has ability to update XML data.
But when they save invalid data it will be saved.
Validation doesn’t work.
How I can validate entry every time when they try to update with the schema?
Is that actually possible? Or I have to use javascript validation.

Reply