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;
}