首页 > 其他 > 详细

xml配置文件的读写

时间:2015-04-25 11:58:44      阅读:316      评论:0      收藏:0      [点我收藏+]

using System.Xml;

//----------------------------------------------读出XML文件中的节点值

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Application.StartupPath + "\\" + "STOExpress.ContentPush.WindowsService.Client.exe.config");
//得到顶层节点列表
if (xmlDoc.DocumentElement != null) {
XmlNodeList topM = xmlDoc.DocumentElement.ChildNodes;
foreach (XmlElement el in from XmlElement element in topM where element.Name.ToLower() == "appsettings" select element.ChildNodes into nodelist where nodelist.Count > 0 from XmlElement el in nodelist where el != null select el) {
if (el.Attributes["key"].Value == "SecurityKey") {
txtSecurityKey.Text = el.Attributes["value"].Value;
}
if (el.Attributes["key"].Value == "ClientNo") {
txtClientCode.Text = el.Attributes["value"].Value;
}
if (el.Attributes["key"].Value == "ClientType") {
txtClientType.Text = el.Attributes["value"].Value;
}
}
}

//---------------------------------------------写入XML文件的值

XmlDocument xmlDoc = new XmlDocument();

xmlDoc.Load(Application.StartupPath + "\\" + "STOExpress.ContentPush.WindowsService.Client.exe.config");
//得到顶层节点列表
if (xmlDoc.DocumentElement != null) {
XmlNodeList topM = xmlDoc.DocumentElement.ChildNodes;
foreach (XmlElement el in from XmlElement element in topM where element.Name.ToLower() == "appsettings" select element.ChildNodes into nodelist where nodelist.Count > 0 from XmlElement el in nodelist where el != null select el) {
if (el.Attributes["key"].Value == "SecurityKey"){
el.Attributes["value"].Value = txtSecurityKey.Text.Trim();
}
if (el.Attributes["key"].Value == "ClientNo") {
el.Attributes["value"].Value = txtClientCode.Text.Trim();
}
if (el.Attributes["key"].Value == "ClientType"){
el.Attributes["value"].Value = txtClientType.Text.Trim();
}
}
}
xmlDoc.Save(configFileName);

 

xml配置文件的读写

原文:http://www.cnblogs.com/qingqingqing/p/4455392.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!