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");  

posted @ 2010-01-02 12:03  greencolor  阅读(247)  评论(0编辑  收藏  举报