xml delete
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("bookstore.xml");
XmlNodeList xnl = xmlDoc.SelectSingleNode("bookstore").ChildNodes;
foreach (XmlNode xn in xnl)
{
XmlElement xe = (XmlElement)xn;
if (xe.GetAttribute("genre") == "fantasy")
{
xe.RemoveAttribute("genre");//删除genre属性
}
else if (xe.GetAttribute("genre") == "update红")
{
xe.RemoveAll();//删除该节点的全部内容
}
}
xmlDoc.Save("bookstore.xml");