<zong> 
            <siteMapNode  title="韩奥采暖炉">  
                      <siteMapNode title="电采暖炉" url="aa.aspx" /> 
                   <siteMapNode title="燃气采暖炉" url="aa.aspx" />   这个怎么删除? 
              <siteMapNode>             <siteMapNode  title="韩奥热水器">  
                      <siteMapNode title="即热式" url="aa.aspx" /> 
                     <siteMapNode title="预热式" url="aa.aspx" />   
              <siteMapNode>
    </zong> ***************  代码   *******************
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(Server.MapPath("../XMLFileIndex.xml"));
        XmlNode root = xmlDoc.SelectSingleNode("siteMapNode");
        XmlNodeList xnl = root.SelectSingleNode("siteMapNode").ChildNodes;
        for (int i = 0; i < xnl.Count; i++)
        {
            XmlElement xe = (XmlElement)xnl.Item(i);
            if (xe.GetAttribute("title") == "燃气采暖炉")
            {
                root.RemoveChild(xe);
                if (i < xnl.Count) i = i - 1;
            }
        }
        xmlDoc.Save(Server.MapPath("../XMLFileIndex.xml")); 

解决方案 »

  1.   

    xml文件有问题!格式好像都不正确!
      

  2.   

    XmlNodeList xnl = root.SelectSingleNode("siteMapNode").ChildNodes
    这里貌似要改成
    XmlNodeList xnl = root.SelectSingleNode("zong").ChildNodes
      

  3.   

    正确的:        XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(Server.MapPath("../XMLFileIndex.xml"));
            XmlNode root = xmlDoc.SelectSingleNode("zong");
            XmlNodeList roottwo=root.ChildNodes;
                    for (int j = 0; j < roottwo.Count; j++)
            {
               XmlNodeList xnl=roottwo[j].ChildNodes;
               for (int i = 0; i < xnl.Count; i++)
               {
                   XmlElement xe = (XmlElement)xnl.Item(i);
                   if (xe.GetAttribute("title") == typeid)
                   {
                       roottwo[j].RemoveChild(xe);
                       if (i < xnl.Count) i = i - 1;
                   }
               }        }
            xmlDoc.Save(Server.MapPath("../XMLFileIndex.xml"));