C# 读取与修改xml一个节点的值

来源:互联网 发布:天狼星加密软件 编辑:程序博客网 时间:2024/06/04 18:11

XML文件如下:

[html] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <root>  
  3.    
  4.   <transDate>2014-12-18</transDate>  
  5. </root>  

C#读取与修改

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. string xmlpath = System.AppDomain.CurrentDomain.BaseDirectory + "config.xml";  
  2.            XmlDocument doc = new XmlDocument();  
  3.            doc.Load(xmlpath);  
  4.            XmlNode xn = doc.SelectSingleNode("//transDate");  
  5.            string transDate = xn.InnerText;  

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. xn.InnerText = value;  
  2. doc.Save(xmlpath);  
2 0