string filepath = "" ;  // Your file path
            XmlDocument doc = new XmlDocument();
            doc.Load(filepath);
            XmlNode xn = doc.ChildNodes[1].ChildNodes[1].ChildNodes[0].ChildNodes[0];            List<XmlNode> lx=new List<XmlNode>();
            for (int i = 0; i < xn.ChildNodes.Count; i++)
{
                lx.Add(xn.ChildNodes[i]);  
}            foreach (var item in lx)
            {
                if (item.Name=="moi"&&item.Attributes["xsi:type"].Value=="APPCERT")
                {
                    xn.RemoveChild(item);
                }
            }            doc.Save(filepath);
            

解决方案 »

  1.   

    我还说你那个怎么结贴了,原来又发了一个。之前没在额。
    我这个比楼上那位稍微简洁了一点儿string xmlpath = @"F:\Test\Test\Test\XMLFile1.xml";
                XmlDocument xml = new XmlDocument();
                xml.Load(xmlpath);//加载xml文件,xmlpath为xml文件的路径
                XmlNode key = xml.ChildNodes[1].ChildNodes[1].ChildNodes[0].ChildNodes[0];//<module xsi:type="LTESiteModule">
                XmlNodeList nodes = key.ChildNodes;
                for (int i = 0; i < nodes.Count; i++)
                {
                    XmlElement node = (XmlElement)nodes[i];
                    if (node.Name == "moi" && node.GetAttribute("xsi:type") == "APPCERT")
                    {
                        key.RemoveChild(node);
                        i -= 1;
                    }
                }
                xml.Save(xmlpath);
      

  2.   

    如果有多个<subsession></subsession>,代码怎么写呢
      

  3.   

                string xmlpath = @"F:\Test\Test\Test\XMLFile1.xml";
                XmlDocument xml = new XmlDocument();
                xml.Load(xmlpath);//加载xml文件,xmlpath为xml文件的路径
                for (int j = 1; j < xml.ChildNodes[1].ChildNodes.Count; j++)//遍历session
                {
                    XmlNode key = xml.ChildNodes[1].ChildNodes[j].ChildNodes[0].ChildNodes[0];
                    XmlNodeList nodes = key.ChildNodes;
                    for (int i = 0; i < nodes.Count; i++)
                    {
                        XmlElement node = (XmlElement)nodes[i];
                        if (node.Name == "moi" && node.GetAttribute("xsi:type") == "APPCERT")
                        {
                            key.RemoveChild(node);
                            i -= 1;
                        }
                    }
                }
                xml.Save(xmlpath);
      

  4.   


                string xmlpath = @"F:\Test\Test\Test\XMLFile1.xml";
                XmlDocument xml = new XmlDocument();
                xml.Load(xmlpath);//加载xml文件,xmlpath为xml文件的路径
                for (int j = 1; j < xml.ChildNodes[1].ChildNodes.Count; j++)//遍历session
                {
                    XmlNode key = xml.ChildNodes[1].ChildNodes[j].ChildNodes[0].ChildNodes[0];
                    XmlNodeList nodes = key.ChildNodes;
                    for (int i = 0; i < nodes.Count; i++)
                    {
                        XmlElement node = (XmlElement)nodes[i];
                        if (node.Name == "moi" && node.GetAttribute("xsi:type") == "APPCERT")
                        {
                            key.RemoveChild(node);
                            i -= 1;
                        }
                    }
                }
                xml.Save(xmlpath);
      

  5.   

    http://blog.csdn.net/jiankunking/article/details/1799
    http://blog.csdn.net/jiankunking/article/details/17992745
    http://blog.csdn.net/jiankunking/article/details/17992793
    可以看看这个