XmlDocument configXml = new XmlDocument();
string fileName = "";
if (File.Exists(fileName))
{
configXml.Load(fileName);
}
XmlDocument xmlDoc = configXml;
XmlNode root = xmlDoc.SelectSingleNode("nodes");
XmlNodeList rootsubs = root.ChildNodes;
XmlNode node = rootsubs[i];
XmlNode key = node.SelectSingleNode(pair[j].Key);
//删除
root.RemoveChild(node);
//添加新的节点
XmlElement xe = xmlDoc.CreateElement("node");//创建一个<book>节点
XmlElement xesub1 = xmlDoc.CreateElement("CaseID");
xesub1.InnerText = this.CaseID;//设置文本节点
xe.AppendChild(xesub1);//添加到<book>节点中
root.AppendChild(xe);//添加到<bookstore>节点中
xmlDoc.Save(System.Windows.Forms.Application.ExecutablePath + ".xml");
try
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(System.Windows.Forms.Application.ExecutablePath + ".config");
XmlNodeList nodeList = xmlDoc.GetElementsByTagName("Customs");
foreach (XmlNode xn in nodeList)//遍历所有子节点
{
if (xn.NodeType == XmlNodeType.Element)
{
XmlElement xe = (XmlElement)xn;
if (xe.GetAttribute("Value") == oldValue)
{
xn.ParentNode.RemoveChild(xe);
break;
}
}
}
xmlDoc.Save(System.Windows.Forms.Application.ExecutablePath + ".config");
}
XmlElement xr = (XmlElement)xd.SelectSingleNode("CONFIG");
XmlElement xmllocation = (XmlElement)xr.SelectSingleNode("LOCATION");
xmllocation.InnerXml = location;
xd.GetElementsByTagName("LOCATION")[0].InnerXml = location;