实例:删除所有节点
private void button1_Click(object sender, EventArgs e)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("f:\\books.xml");
XmlElement root = xmlDoc.DocumentElement;
root.RemoveAll();
xmlDoc.Save("F:\\books.xml");
}
实例:删除最后一个节点
private void button1_Click(object sender, EventArgs e)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("f:\\books.xml");
XmlElement root = xmlDoc.DocumentElement;
if (root.HasChildNodes)
{
XmlNode book = root.LastChild;
root.RemoveChild(book);
xmlDoc.Save("f:\\books.xml");
}
}