日期:2014-05-17  浏览次数:21045 次

Xml节点为什么删除不掉
        private string xmlPath=Application.StartupPath.Replace("bin\\Debug","") + "InstallFiles\\BookMarks.xml";
        private XmlDocument _XmlDoc;
        public XmlDocument XmlDoc 
        {
            get 
            {
                _XmlDoc = new XmlDocument();
                _XmlDoc.Load(xmlPath);
                return _XmlDoc;
            }
        }
       public bool DelBookName(string nodeName) 
        {
            XmlNodeList xmlNodes = XmlDoc.SelectSingleNode("BookMarks").ChildNodes;
            foreach (XmlNode node in xmlNodes)
            {
                XmlElement xmlEle = (XmlElement)node;
                if (xmlEle.GetAttribute("Name").Equals(nodeName))
                {
                    node.ParentNode.RemoveChild(node);
                    //xmlEle.ParentNode.RemoveChild(node);
                    XmlDoc.Save(xmlPath);
                    return true;
                }
             }
             return false;
        }
xml

------解决方案--------------------
你每次得到的XmlDoc都是一个新的实例。