using System;
using System.IO;
using System.Xml;public class Sample { public static void Main() { XmlDocument doc = new XmlDocument();
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
"<title>Pride And Prejudice</title>" +
"</book>"); XmlNode root = doc.DocumentElement; //Remove the title element.
root.RemoveChild(root.FirstChild); Console.WriteLine("Display the modified XML...");
doc.Save(Console.Out); }
}
using System.IO;
using System.Xml;public class Sample { public static void Main() { XmlDocument doc = new XmlDocument();
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
"<title>Pride And Prejudice</title>" +
"</book>"); XmlNode root = doc.DocumentElement; //Remove the title element.
root.RemoveChild(root.FirstChild); Console.WriteLine("Display the modified XML...");
doc.Save(Console.Out); }
}
如果 xml 文档很大的话,还是用 XmlReader,但是没必要删除前面的节点啊,反正是循环,判断下节点名称是不是item 就可以啊,还有,除非是使用读片断的方式,否则根节点是必须的。