如何从XmlDocument加载的XML中删除节点

时间:2016-06-17 13:09:27

标签: c# xml windows-8 windows-phone xmldocument

我在一个更大的文档中重复了如下所示的xml片段。如何使用XmlDocument删除所有出现的welltotalfee

<res>
  <pay>
    <well/>
    <total/>
    <fee/>
    <tit>
        <qr>asdf</qr>
        <id>
            <num/>
        </id>
    </tit>
  </pay>
</res>

1 个答案:

答案 0 :(得分:0)

将xml加载到XDocument(https://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument(v=vs.110).aspx)中,然后使用linq查找并删除相关节点。

然后它只是XDocument deleting a node

的副本

如果你真的想使用XMLDocument而不是XDocument类,那么这是Removing nodes from an XmlDocument的重复