修改xml的實例JS版

 JScript code
//load xml
loadXML    = function(xmlFile)
{
    var xmlDoc;
    if(window.ActiveXObject)
    {
        xmlDoc    = new ActiveXObject('Microsoft.XMLDOM');
        xmlDoc.async    = false;
        xmlDoc.load(xmlFile);
    }
    else if (document.implementation&&document.implementation.createDocument)
    {
        xmlDoc    = document.implementation.createDocument('', '', null);
        xmlDoc.load(xmlFile);
    }
    else
    {
        return null;
    }
    return xmlDoc;
}

//do some checking with the loaded xml file.
checkXMLDocObj    = function(xmlFile)
{
    var xmlDoc    = loadXML(xmlFile);
    if(xmlDoc==null)
    {
        alert('Reading XML file is not supported by your browser, please use IE5.0 or above! ');
        window.location.href='error.page';
    }
   
    if (xmlDoc.parseError.errorCode!=0)
    {
        var error = xmlDoc.parseError;
        alert(error.reason);
        return;
    }
    return xmlDoc;
}

 checkUser= function(password)
        {
            var xmlDoc    = checkXMLDocObj('data.config');
            var nodeList = xmlDoc.selectNodes("//name");  //look for the nodes named of "name"
            for (var i=0; i < nodeList.length; i++) 
            {
                var nameNode = nodeList.item(i);
                if (nameNode.text == this.name)
                {
                    var pwdNode = nameNode.nextSibling;
                    if (pwdNode.text == password)
                    {
                        return true;
                    }
                }
            }
            alert('wrong password!');
            return false;
        }

 

 

發佈了42 篇原創文章 · 獲贊 0 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章