Monday, April 21, 2008

Removing Xml element in two ways

<?xml version="1.0" encoding="utf-8" ?><bookstore> <books> <book genre="reference"> <title>World Atlas</title> </book> <book genre="reference"> <title>World Atlas</title> </book> </books></bookstore>


XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath("test.xml"));
XmlElement root = xmldoc.DocumentElement;


root.RemoveChild(root.SelectNodes("books/book"));
root.RemoveChild(root.RemoveChild(root.FirstChild));