I have a valid xml and schema.
I put them together in javascript and generate html.
Like this:
- 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.