XML文件更改插入

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

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念