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;
}
<?xml version="1.0" encoding="gb2312"?>
<Config>
<Setting genre="fantasy" ISBN="2-2312-2">
<author>Eva</author>
<price>56.5</price>
</Setting>
<SNScanBeep>True</SNScanBeep>
<NeedPNO>True</NeedPNO>
</Config>