Today looking for the way how to extract <!-- --> from Visual Basic for Applications (not C#), I have found also nodeTypeString property, but it takes more space. Here is an example in VBA:
Dim xmldoc As New MSXML2.DOMDocument30 Dim oNodeList As IXMLDOMSelection Dim node As IXMLDOMNode Dim i As Long Dim FileName As String, FileName1 As String FileName = "..." ' Source FileName2 = "..." ' Target xmldoc.async = False ' ? xmldoc.Load FileName If (xmldoc.parseError.errorCode <> 0) Then Exit Sub ' or Function Set oNodeList = xmldoc.selectNodes("//*") '' all nodes For i = 0 To oNodeList.length - 1 With oNodeList(i) For Each node In .childNodes If node.nodeTypeString = "comment" Then .removeChild node Next End With Next xmldoc.Save FileName2 Set oNodeList = Nothing ' ? Set xmldoc = Nothing
It omitts document top parent comment nodes, but they can be retrieved somehow directly if needed, for example using With xmldoc.documentElement.childNodes.