validateXml.js 817 Bytes
Newer Older
CED SA's avatar
CED SA committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
objArgs = WScript.Arguments;

var sOutput = validateFile(objArgs(0));

if (sOutput != "") {
	WScript.Echo(sOutput);
}

function validateFile(strFile)
{
    // Create an XML DOMDocument object.
    var x = new ActiveXObject("MSXML2.DOMDocument.4.0");

    //Load and validate the specified file into the DOM.
    x.async = false;
    x.validateOnParse = true;
    x.resolveExternals = true;
    x.load(strFile);

    // Return validation results in message to the user.
    if (x.parseError.errorCode != 0)
    {
        return("Errore di validazione file: " + strFile + 
               "\n=====================" +
               "\nMotivo: " + x.parseError.reason + 
               "\nSorgente: " + x.parseError.srcText + 
               "\nLinea: " + x.parseError.line + "\n");
    }
    else 
        return("");
}