asp.net xml

   #region 记录用户在本页的xml文档
    public void loadXmlDoc()
    {
        xmlDoc = new XmlDocument();
        xmlDoc.Load(Server.MapPath(@"xmlfile/curUser.xml"));
    }

    public void checkNode()
    {
        //检查用户信息是否已经存在
        XmlNode root=xmlDoc.DocumentElement;
        if (root.ChildNodes.Count == 0)
        {
            Page.Response.Write("<script>alert('empty');</script>");
            addNode();
        }
        else
        {
            foreach (XmlNode node in root.ChildNodes)
            {
                if (node.FirstChild.Name == "uid" && node.FirstChild.InnerText.Equals(uid.ToString()))
                {
                    Page.Response.Write("<script>alert(" +node.FirstChild.Name+"--" +node.FirstChild.InnerText + ");</script>");
                    //已经有了用户信息的节点
                    //Page.Response.Write("<script>alert(" + node.FirstChild.InnerText + ");</script>");
                    exist = 1;
                    break;
                }
                else
                {

                }
            }
            Page.Response.Write("<script>alert(" + exist.ToString() + ");</script>");
            if (exist == 1)
            {
                //已经存在了用户信息
            }
            else
            {
                //不存在用户信息
                addNode();
            }
        }
    }
    public void addNode()
    {
        XmlElement eleUser = xmlDoc.CreateElement("user");
        XmlElement eleAccount = xmlDoc.CreateElement("account");
        XmlElement eleUid = xmlDoc.CreateElement("uid");
        XmlElement eleUpdate = xmlDoc.CreateElement("update");
        eleAccount.InnerText = account;
        eleUid.InnerText = uid;
        eleUpdate.InnerText = System.DateTime.Now.ToString();
        eleUser.AppendChild(eleUid);
        eleUser.AppendChild(eleAccount);
        eleUser.AppendChild(eleUpdate);
        xmlDoc.DocumentElement.AppendChild(eleUser);
        xmlDoc.Save(Server.MapPath(@"xmlfile/curUser.xml"));

    }
    //更新用户的在新时间

    #endregion

本文使用Blog_Backup未注册版本导出,请到soft.pt42.com注册。

你可能感兴趣的:(asp.net)