Using schema validation for update

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Korol
    New Member
    • Oct 2005
    • 2

    #1

    Using schema validation for update

    I have a valid xml and schema.
    I put them together in javascript and generate html.
    Like this:
    Code:
    function initAdmin() {
      var xslDoc
      strFile="Simple.Config.xml"
      strSchema="SimpleSchemaConfig.xsd";
    
      if (ValidateShema(strFile,strSchema)==true){
          xmlDoc = new ActiveXObject('MSXML2.DOMDocument.4.0');
          xmlDoc.async = false;
    
          xslDoc = new ActiveXObject('MSXML2.DOMDocument.4.0');
          xslDoc.async = false;
    
          AppPath = xmlDoc.url;
          xmlDoc.loadXML(xmlDoc.documentElement.transformNode(xslDoc));
          xslDoc.load("FileTree.xsl");
          folderTree.innerHTML = xmlDoc.documentElement.transformNode(xslDoc);  
    }
    }
    
    function ValidateShema(strFile,strSchema){ 
    
    try
    {
           xmlDoc              = new ActiveXObject("MSXML2.DOMDocument.4.0");
           schemaCache         = new ActiveXObject("MSXML2.XMLSchemaCache.4.0");
         
           xmlDoc.async            = false;
           xmlDoc.resolveExternals = false;
           xmlDoc.validateOnParse  = false;
         
           schemaCache.add("",strSchema);
         
           xmlDoc.schemas = schemaCache;
           xmlDoc.validateOnParse = true;
           if (xmlDoc.load(strFile)) {       
             displayError("xml is valid.");
             return true;
           }
           else {
             if (xmlDoc.parseError.errorCode != 0) {
               displayError("Validation failed on " + strFile + 
                    "\nReason: " + xmlDoc.parseError.reason + 
                    "\nSource: " + xmlDoc.parseError.srcText + 
                    "\nLine: " + xmlDoc.parseError.line + "\n");
                    isValid=0;
                    return false;
             }
           }
    }
    catch(ex)
    {
         alert("Error: " + ex.message)
    }
    }
    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.
    Last edited by Dormilich; Jan 9 '09, 07:06 AM. Reason: replaced [quote] with [code] tags
Working...