private void UpdateConfig(string Xvalue)
{
XmlDocument doc = new XmlDocument();
doc.Load(System.Windows.Forms.Application.StartupPath+" //MapInfo.xml");
XmlNode node = doc.SelectSingleNode(@"//add[@key='MapPath']");
XmlElement ele = (XmlElement)node;
ele.SetAttribute("value",Xvalue);
doc.Save(System.Windows.Forms.Application.StartupPath+" //MapInfo.xml");
}
private string ReadConfig()
{
XmlDocument doc = new XmlDocument();
doc.Load(System.Windows.Forms.Application.StartupPath+" //MapInfo.xml");
XmlNode node = doc.SelectSingleNode(@"//add[@key='MapPath']");
XmlElement ele = (XmlElement)node;
string retVal=ele.GetAttribute("value");
return retVal;
}
{
XmlDocument doc = new XmlDocument();
doc.Load(System.Windows.Forms.Application.StartupPath+" //MapInfo.xml");
XmlNode node = doc.SelectSingleNode(@"//add[@key='MapPath']");
XmlElement ele = (XmlElement)node;
ele.SetAttribute("value",Xvalue);
doc.Save(System.Windows.Forms.Application.StartupPath+" //MapInfo.xml");
}
private string ReadConfig()
{
XmlDocument doc = new XmlDocument();
doc.Load(System.Windows.Forms.Application.StartupPath+" //MapInfo.xml");
XmlNode node = doc.SelectSingleNode(@"//add[@key='MapPath']");
XmlElement ele = (XmlElement)node;
string retVal=ele.GetAttribute("value");
return retVal;
}
本文介绍了一种使用C#进行XML文件配置项读取和更新的方法。通过实例展示了如何加载XML文档、选择特定节点并修改其属性,以及保存更改后的XML文件。此方法适用于需要动态配置应用程序参数的场景。
1177

被折叠的 条评论
为什么被折叠?



