更新xml
一、
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(path);
XmlNode memberlist = xmlDoc.SelectSingleNode("works");
XmlNodeList nodelist = memberlist.ChildNodes;
foreach (XmlNode node in nodelist)
{
if (node.Attributes["state"].InnerText.ToString().Equals("1"))
{
if (node.SelectSingleNode("XmliD").InnerText == xmlid)
{
node.Attributes["state"].InnerText = "0";
}
break;
}
}
xmlDoc.Save(path);
二、
XmlDocument myCha = new XmlDocument();
try
{
myCha.Load(path);
}
catch (Exception e)
{
if (e != null)
{
return "没有该文件";
}
}
myCha.Load(path);
//2.获得根节点
XmlNode node = myCha.DocumentElement;
foreach (XmlNode ShowList in node.ChildNodes)
{
if (ShowList.Attributes["state"].InnerText.ToString().Equals("1"))
{
foreach (XmlNode work in ShowList.ChildNodes)
{
switch (work.Name)
{
case "ip":
work.InnerText=pa.ip;
break;
case "ku":
work.InnerText = pa.ku;
break;
case "name":
work.InnerText = pa.name;
break;
case "passwrod":
work.InnerText = pa.passwrod;
break;
}
}
}
}
myCha.Save(path);