how to remove nodes in an xml that is inside another xml

陌路散爱 提交于 2020-01-17 13:47:01

问题


I have an xml as an value of an element inside a Main xml. I want to scrub off or delete a node within the inner xml. How do I achieve that ?

For removing a node in main xml I am doing

var result = doc.Descendants("node1").Where(x => x.Attribute("id").Value == "002");
 if (result != null)
                    {
                        result.Remove();
                    }

Here is my XML :

<?xml version="1.0" encoding="utf-16"?>
<root>
    <node1>id="001" version="1.0"</node1>
    <node2>id="002" version="1.0"</node1>
    <report>raw = "<response = "10"><innerxml><prod>date = "18082016" name="pqr"</prod><seg1>id="002" name = "sqs"</seg1></innerxml></response>"</report>
</root>

回答1:


Your code is correct but your xml is not. the XML should be like:

<?xml version="1.0" encoding="utf-16"?>
<root>
    <node1 id="001" version="1.0"></node1>
    <node2 id="002" version="1.0"></node2>
</root>


来源:https://stackoverflow.com/questions/38960338/how-to-remove-nodes-in-an-xml-that-is-inside-another-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!