C# 操作xml文件

  /// <summary>
        /// 修改XML
        /// </summary>
        /// <param>test</param>
        public static void ChangeXml(string test)
        {
            string xmlPath = "config";//当前文件夹下的config
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(xmlPath);
            XmlNodeList settings = xmlDoc.SelectNodes("configuration/applicationSettings/setting");
            foreach (XmlNode node in settings)
            {
                XmlNode valueNode = node.SelectSingleNode("value");
                string[] uri = valueNode.InnerText.Split('/');
                valueNode.InnerText = "http://" + test + "/" + uri[uri.Length - 1];
            }
            xmlDoc.Save(configPath);
        }

posted @ 2015-02-03 14:18  徐本县  阅读(106)  评论(0)    收藏  举报