XML文件更改插入
发布时间:2020-12-16 06:00:12 所属栏目:百科 来源:网络整理
导读:XmlDocument doc = new XmlDocument(); doc.Load(xmlPaht); XmlNodeList node = doc.SelectNodes("//Staff[Staffid='" + id + "']"); if (node.Count == 0) { //没有找到 XmlNode root = doc.CreateNode(XmlNodeType.Element,"Staff",null); XmlNode Staffid
XmlDocument doc = new XmlDocument();
doc.Load(xmlPaht);
XmlNodeList node = doc.SelectNodes("//Staff[Staffid='" + id + "']");
if (node.Count == 0)
{
//没有找到
XmlNode root = doc.CreateNode(XmlNodeType.Element,"Staff",null);
XmlNode Staffid = doc.CreateNode(XmlNodeType.Element,"Staffid",null);
Staffid.InnerText = id;
XmlNode LoginCount = doc.CreateNode(XmlNodeType.Element,"LoginCount",null);
LoginCount.InnerText = "1";
XmlNode LastLoginTime = doc.CreateNode(XmlNodeType.Element,"LastLoginTime",null);
LastLoginTime.InnerText = DateTime.Now.ToString("yyy-MM-dd hh:mm:ss");
root.AppendChild(Staffid);
root.AppendChild(LoginCount);
root.AppendChild(LastLoginTime);
doc.DocumentElement.AppendChild(root);
}
else
{
foreach (XmlNode Child in node)
{
if (Child.Name == "LoginCount")
{
Child.InnerText = (int.Parse(Child.InnerText) + 1).ToString();
}
if (Child.Name == "LastLoginTime")
{
Child.InnerText = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
}
}
}
doc.Save(xmlPaht); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
