How to remove all child nodes of an XmlElement, but keep all attributes?

后端 未结 3 393
情话喂你
情话喂你 2021-01-07 23:00

How to remove all child nodes of an XmlElement, but keep all attributes?

Note, that XmlElement.RemoveAll also removes all attributes. What is a clean, e

3条回答
  •  攒了一身酷
    2021-01-07 23:26

    For a truly efficient solution:

    e.IsEmpty = true;
    

    is your fastest and simplest option. It does exactly what you requested: all inner text and nested elements are discarded, while attributes are retained.

提交回复
热议问题