c# - Remove node from xmlDocument -


this question has answer here:

i trying remove nodes xml document based on input getting below error...

the node removed not child of node.

 xmldocument document = new xmldocument();         document.load(filepath);         if (document == null)             throw new exception("unable load document.");          foreach (string xpath in xpaths)         {              xmlnodelist oldchild = document.selectnodes(xpath, mgr);             if (oldchild != null)             {                 foreach (xmlnode child in oldchild)                 {                     document.removechild(child);                 }             }         }          document.save(filepath); 

can me missign here.

the removechild method working on direct child of node. trying remove inner (not first generation) node accessing root node - document. trick here parent node , remove child it.

child.parentnode.removechild(child) 

Comments

Popular posts from this blog

Python Kivy ListView: How to delete selected ListItemButton? -

asp.net mvc 4 - A specified Include path is not valid. The EntityType '' does not declare a navigation property with the name '' -