1. 程式人生 > >C# 讀取與修改xml一個節點的值

C# 讀取與修改xml一個節點的值

XML檔案如下:

<?xml version="1.0" encoding="utf-8"?>
<root>
 
  <transDate>2014-12-18</transDate>
</root>

C#讀取與修改
 string xmlpath = System.AppDomain.CurrentDomain.BaseDirectory + "config.xml";
            XmlDocument doc = new XmlDocument();
            doc.Load(xmlpath);
            XmlNode xn = doc.SelectSingleNode("//transDate");
            string transDate = xn.InnerText;

xn.InnerText = value;
doc.Save(xmlpath);