博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# 读写XML文件,用于配置文件
阅读量:2065 次
发布时间:2019-04-29

本文共 1513 字,大约阅读时间需要 5 分钟。

 

public static void UpdateSetValue(string tagName, string value)        {            XmlDocument xmlDoc = new XmlDocument();            xmlDoc.Load("config.xml"); //加载xml文件           // XmlNode node = xmlDoc.GetElementById("Config");            XmlNodeList nodes = xmlDoc.SelectSingleNode("Config").ChildNodes;                         for (int i = 0; i < nodes.Count; i++)            {                MessageBox.Show(nodes[i].Name);                if (nodes[i].Name.Equals(tagName))                {                    nodes[i].InnerText = value;                }             }            try            {                //保存上面的修改                    xmlDoc.Save("config.xml");            }            catch (Exception e)            {                throw e;            }        }        public static string GetNodeValue(string tagName)        {            string result = "";            XmlDocument xmlDoc = new XmlDocument();            xmlDoc.Load("config.xml"); //加载xml文件            // XmlNode node = xmlDoc.GetElementById("Config");            XmlNodeList nodes = xmlDoc.SelectSingleNode("Config").ChildNodes;            for (int i = 0; i < nodes.Count; i++)            {                 if (nodes[i].Name.Equals(tagName))                {                    result = nodes[i].innerText;                   return result ;                                   }             }            return result;        }

Eva
56.5
True
True

转载地址:http://lhumf.baihongyu.com/

你可能感兴趣的文章
Leetcode C++《热题 Hot 100-13》234.回文链表
查看>>
Leetcode C++《热题 Hot 100-14》283.移动零
查看>>
Leetcode C++《热题 Hot 100-15》437.路径总和III
查看>>
Leetcode C++《热题 Hot 100-17》461.汉明距离
查看>>
Leetcode C++《热题 Hot 100-18》538.把二叉搜索树转换为累加树
查看>>
Leetcode C++《热题 Hot 100-19》543.二叉树的直径
查看>>
Leetcode C++《热题 Hot 100-21》581.最短无序连续子数组
查看>>
Leetcode C++《热题 Hot 100-22》2.两数相加
查看>>
Leetcode C++《热题 Hot 100-23》3.无重复字符的最长子串
查看>>
Leetcode C++《热题 Hot 100-24》5.最长回文子串
查看>>
Leetcode C++《热题 Hot 100-26》15.三数之和
查看>>
Leetcode C++《热题 Hot 100-27》17.电话号码的字母组合
查看>>
Leetcode C++《热题 Hot 100-28》19.删除链表的倒数第N个节点
查看>>
Leetcode C++《热题 Hot 100-29》22.括号生成
查看>>
Leetcode C++《热题 Hot 100-40》64.最小路径和
查看>>
Leetcode C++《热题 Hot 100-41》75.颜色分类
查看>>
Leetcode C++《热题 Hot 100-42》78.子集
查看>>
Leetcode C++《热题 Hot 100-43》94.二叉树的中序遍历
查看>>
Leetcode C++ 《第175场周赛-1 》5332.检查整数及其两倍数是否存在
查看>>
Leetcode C++ 《第175场周赛-2 》5333.制造字母异位词的最小步骤数
查看>>