static void RemoveComments(Document doc) { // Collect all comments in the document NodeCollection comments = doc.GetChildNodes(NodeType.Comment, true); // Remove all comments. comments.Clear(); } // ExEnd:RemoveComments