zoukankan      html  css  js  c++  java
  • XML操作App.config的类

    public class DoConfig
        {
            public static void Editconfig(string Key,string Value)                      
            {
                XmlDocument xmldoc = new XmlDocument();
                string filePath = Application.ExecutablePath + ".config";
                xmldoc.Load(filePath);

                XmlNodeList topM = xmldoc.DocumentElement.ChildNodes;
                foreach (XmlElement element in topM)
                {
                    if (element.Name.ToLower() == "appsettings")     //找到要改写的字段名 
                    {
                        XmlNodeList _node = element.ChildNodes;
                        if (_node.Count > 0)
                        {
                            foreach (XmlElement el in _node)
                            {
                                //el.Attributes[Key].Value = Value;                                                                 //查找并改写 
                                if (el.Attributes["key"].Value == Key)
                                    el.Attributes["value"].Value = Value;
                            }
                        }
                    }
                }
                xmldoc.Save(filePath);       //保存改写文件 
            }
        }
  • 相关阅读:
    python2和3切换时的几个注意点会报错
    Python异常UnicodeEncodeError 'gbk' codec can't encode character 'xa0'
    python爬虫使用Xpath爬取指定位置的内容
    问题账户需求分析
    2018年春季个人阅读计划
    我们应当怎样做需求分析
    人月神话读后感3
    人月神话读后感2
    线程池
    生产者消费者
  • 原文地址:https://www.cnblogs.com/lds85930/p/1124737.html
Copyright © 2011-2022 走看看