码迷,mamicode.com
首页 > Windows程序 > 详细

C# XML文件操作

时间:2015-08-26 17:55:40      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

 private void SaveXML()
        {
            FileInfo fileInfo = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "list.xml");

            if (fileInfo.Exists)
            {
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(AppDomain.CurrentDomain.BaseDirectory + "list.xml");
                XmlNode xmlNode = xmlDocument.SelectSingleNode("Lists");
                XmlNodeList xmlNodeList = xmlNode.SelectNodes("List");

                foreach (XmlNode node in xmlNodeList)
                {
                    XmlElement element = (XmlElement)node;
                    element["Time"].InnerText = "12341";
                }
                xmlDocument.Save(AppDomain.CurrentDomain.BaseDirectory + "list.xml");
            }
        }


  private void GetXML()
        {
            FileInfo fileInfo = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "list.xml");
            if (fileInfo.Exists)
            {
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(AppDomain.CurrentDomain.BaseDirectory + "list.xml");
                XmlNode xmlNode = xmlDocument.SelectSingleNode("Lists");
                XmlNodeList nodes = xmlNode.SelectNodes("List");

                foreach (XmlNode node in nodes)
                {
                    XmlElement element = (XmlElement)node;
                    string str = element["Time"].InnerText;
                    MessageBox.Show(str);
                }
            }
        }


版权声明:本文为博主原创文章,未经博主允许不得转载。

C# XML文件操作

标签:

原文地址:http://blog.csdn.net/ilipan/article/details/48006477

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!