public DataSettingWebService()
{
thisfileName =thisServer MapPath(@/ClientBin/ServerData/UserMessagexml);
thisdoc = new XmlDocument();
thisdocLoad(fileName);
}
添加元素
public bool CreateNewUser(string userNamestring passWorld)
{
try{
if (userName == || passWorld == )
{
return false;
}
XmlElement root = docDocumentElement;
XmlElement newUser = docCreateElement(User);
newUserSetAttribute(username userName);
newUserSetAttribute(passworld passWorld);
newUserSetAttribute(abilitylevel );
newUserSetAttribute(registertime DateTimeNowToString());
for (int i = ; i <= ; i++)
{
XmlElement newLevel = docCreateElement(Level);
newLevelSetAttribute(id iToString());
newLevelSetAttribute(score );
newLevelSetAttribute(usetime );
newLevelSetAttribute(clicknum );
newLevelSetAttribute(playtime );
newUserAppendChild(newLevel);
}
rootAppendChild(newUser);
docSave(fileName);
return true ;
}
catch
{
return false ;
}
}
修改更新属性值
public bool UpdateUserGrade(string userName int score string useTime string clickNum int levelId)
{
bool IsAbilityLevelChange = false;
XmlNodeList nodelist = docGetElementsByTagName(User);
foreach (XmlNode xdu in nodelist)
{
if (xduAttributes[username]Value == userName)
{
XmlElement xeu = xdu as XmlElement;
if (levelId > ConvertToInt(xeuAttributes[abilitylevel]Value))
{
xeuSetAttribute(abilitylevel levelIdToString());
IsAbilityLevelChange = true;
}
nodelist = xeuGetElementsByTagName(Level);
foreach (XmlNode xdl in nodelist)
{
if (xdlAttributes[id]Value == levelIdToString())
{
if (score > ConvertToInt(xdlAttributes[score]Value))
{
XmlElement xel = xdl as XmlElement;
xelSetAttribute(score scoreToString());
xelSetAttribute(usetime useTime);
xelSetAttribute(clicknum clickNum);
xelSetAttribute(playtime DateTimeNowToString());
}
break;
}
}
break;
}
}
docSave(fileName);
return IsAbilityLevelChange;
}