XDocument deleting a node

让人想犯罪 __ 提交于 2019-12-06 04:07:49

untested, but this should work. Let me know if you want it explained.

xdoc.Descendents("Snippet").Where(xe => xe.Attribute("name") != null 
    && xe.Attribute("name").Value == "foreach").Single().Remove()

You can do it simply, at last you should Save file:

       XDocument doc = XDocument.Load("XmlFile1.xml");
        doc.Descendants("Snippet").Where(p => p.Attribute("name") != null 
                                        && p.Attribute("name").Value == "foreach")
                                        .Remove();
        doc.Save("XmlFile1.xml");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!