Remove all comments from XDocument
问题 I am working on reading XDocument. How can I remove all commented lines from XDocument. I have tried with doc.DescendantNodes().Where(x => x.NodeType == XmlNodeType.Comment).Remove(); But this removes only first level nodes with comments and inner level nodes remains as it is. Is there any way to remove all commented lines. I believe there must be!!! ;) Any Solutions. 回答1: Instead of the Where(x => x.NodeType == XmlNodeType.Comment) I would simply use OfType<XComment>() , as in doc