using System.Xml;
string sFile = "TestXml3.xml";
XmlDocument doc=new XmlDocument();
doc.Load(sFile);
XmlElement e = doc.CreateElement("Record");
e.SetAttribute("id","8");
e.SetAttribute("name","A");
e.SetAttribute("title","B");
e.InnerText = "";
doc.DocumentElement.AppendChild(e); XmlElement e2 = (XmlElement)doc.DocumentElement.SelectSingleNode("Record[@id='7']");
if (e2 != null)
{
e2.SetAttribute("name","C");
//doc.Save(Console.Out); doc.DocumentElement.RemoveChild(e2);
//doc.Save(Console.Out);
}
doc.Save(sFile);
string sFile = "TestXml3.xml";
XmlDocument doc=new XmlDocument();
doc.Load(sFile);
XmlElement e = doc.CreateElement("Record");
e.SetAttribute("id","8");
e.SetAttribute("name","A");
e.SetAttribute("title","B");
e.InnerText = "";
doc.DocumentElement.AppendChild(e); XmlElement e2 = (XmlElement)doc.DocumentElement.SelectSingleNode("Record[@id='7']");
if (e2 != null)
{
e2.SetAttribute("name","C");
//doc.Save(Console.Out); doc.DocumentElement.RemoveChild(e2);
//doc.Save(Console.Out);
}
doc.Save(sFile);
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货