**unityUI界面实现XML用户基本信息数据的增删查改以及分页效果**
效果图不小心删了,自己随便构建吧(初学者所写,望谅解,有大佬可以指正那就更好了)
XML文件格式
<?xml version="1.0" encoding="utf-8"?>
<Root>
<user username="安维汀" password="1" phone="额" address="rfrgwrtg" position="gwrtw" sex="男" />
<user username="a" password="b" phone="b" address="b" position="b" sex="男" />
<user username="幸福感和" password="w" phone="w" address="w" position="w" sex="女" />
<user username="RTGWRT " password="x" phone="x" address="x" position="x" sex="女" />
<user username="FGRW " password="5" phone="5" address="5" position="5" sex="男" />
<user username="父物体有" password="p" phone="p" address="p" position="p" sex="男" />
<user username="frrt" password="1" phone="额" address="rfrgwrtg" position="gwrtw" sex="男" />
<user username="gryyu" password="7" phone="7" address="7" position="7" sex="女" />
<user username="grgyryty I" password="1" phone="1" address="1" position="1" sex="男" />
<user username="tyuj " password="w" phone="t" address="o" position="o" sex="女" />
<user username="hjktk " password="z" phone="x" address="c" position="v" sex="男" />
<user username="RFG凤凰网W " password="123" phone="123" address="123" position="123" sex="女" />
<user username="RGW回电话YR" password="HEU " phone="GJERUJ " address="GHEUJ" position="HEU" sex="男" />
<user username="画图" password="t y" phone="te " address="tye " position="yey " sex="男" />
<user username="ad " password="daf " phone="dfqaf " address="dfa " position="dfa " sex="男" />
<user username="fgfg" password="fh " phone="gv" address="vb" position="vb" sex="男" />
<user username="ikk" password="uk " phone="kt " address="utik" position="uit" sex="女" />
<user username="yyuyu" password="ht" phone="hkjjk" address="yuyuu" position="yuyu" sex="女" />
<user username="ttt" password="ghdjg " phone="gghgh" address="hg" position="ghg" sex="男" />
</Root>
添加数据
//注册
public void RegiterUser()
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlPath);
XmlNodeList xmlList = xmlDoc.SelectSingleNode("Root").ChildNodes;//返回根节点下面的所有子节点
foreach (XmlElement item in xmlList)
{
if (item.GetAttribute("username") == username.text)
{
OpenAlertPanel("用户名已经被占用!");
return;
}
}
//保存注册信息
XmlNode root = xmlDoc.SelectSingleNode("Root");
XmlElement user = xmlDoc.CreateElement("user");
user.SetAttribute("username", username.text);
user.SetAttribute("password", password.text);
user.SetAttribute("phone", phone.text);
user.SetAttribute("address", address.text);
user.SetAttribute("position", position.text);
user.SetAttribute("sex", sex.captionText.text);
root.AppendChild(user);
xmlDoc.Save(xmlPath);
OpenAlertPanel("恭喜,注册成功!");
//保存信息后清空控件里面的内容
username.text = "";
password .text = "";
phone.text = "";
address.text = "";
position.text = "";
sex.captionText.text = "";
Button1();
}
删除数据