• XML_操作


    //加载

    protected void Page_Load(object sender, EventArgs e)
            {
                string filePath = Server.MapPath("~/xml/addressList.xml");
                if (!Page.IsPostBack)
                {
                    if (!File.Exists(filePath))
                    {
                        CreteXml();
                    }
                    else
                    {
                        ReadXml();
                    }
                }
            }

    //创建

    private void CreteXml()
            {
                string filePath = Server.MapPath("~/xml/addressList.xml");
                XmlDocument doc = new XmlDocument();
                XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0","utf-8","");
                XmlElement root = doc.CreateElement("addressList");
                root.IsEmpty = false;
                XmlAttribute createTime = doc.CreateAttribute("createTime");
                createTime.Value = DateTime.Now.ToShortDateString();
                root.Attributes.Append(createTime);

                doc.AppendChild(declaration);
                doc.AppendChild(root);

                doc.Save(filePath);
            }

    //读取

            private void ReadXml()
            {
                List<LinkMan> lst = new List<LinkMan>();
                XmlDocument doc = new XmlDocument();
                //加载xml
                doc.Load(Server.MapPath("~/xml/addressList.xml"));
                XmlNodeList nodeList = doc.GetElementsByTagName("linkman");

                foreach (XmlNode node in nodeList)
                {
                    LinkMan linkMan = new LinkMan();
                    if (node.Attributes["name"]!=null)
                    {
                        linkMan.Name = node.Attributes["name"].Value;
                    }
                    lst.Add(linkMan);
                }

                this.GridView1.DataSource = lst;
                this.GridView1.DataBind();
            }

  • 相关阅读:
    vim讲解
    tar常用解包
    linux扩展权限
    为Virtualbox中的Solaris10安装VBoxAdditions
    Solaris10下Telnet、SSH、ftp使用root登录
    linux软链接和硬链接
    curl命令学习(转载的)
    linux磁盘分区fdisk命令详解
    在服务器上排除问题的头五分钟
    Java对文件压缩/加密/解密/解压缩的例子,DES/RSA
  • 原文地址:https://www.cnblogs.com/xiaoxiaomayi/p/2802009.html
Copyright © 2020-2023  润新知