0

I would like a Visual Studio macro to remove all comments from a given XML file. For example, given this:

<?xml version="1.0" encoding="UTF-8" ?>
<!-- 
     Comment 1
-->
<config>
  <!-- Comment 2    -->
  <abortOnConfigurationError>${solr.abortOnConfigurationError:true}</abortOnConfigurationError>
</config>

I would like to get this:

<?xml version="1.0" encoding="UTF-8" ?>

<config>

  <abortOnConfigurationError>${solr.abortOnConfigurationError:true}</abortOnConfigurationError>
</config>

I've searched for editors that do this and VS macros but can't find anything.

Brian Leeming
  • 11,540
  • 8
  • 32
  • 52

1 Answers1

0

I wrote my own:

Sub macro1()
    DTE.ActiveDocument.Selection.StartOfDocument()
    Do While True
        DTE.ExecuteCommand("Edit.Find")
        DTE.Find.FindWhat = "<!--"
        DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
        DTE.Find.MatchCase = False
        DTE.Find.MatchWholeWord = False
        DTE.Find.Backwards = False
        DTE.Find.MatchInHiddenText = False
        DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxLiteral
        DTE.Find.Action = vsFindAction.vsFindActionFind
        If (DTE.Find.Execute() = vsFindResult.vsFindResultNotFound) Then
            Exit Do
        End If
        DTE.Find.FindWhat = "-->"
        If (DTE.Find.Execute() = vsFindResult.vsFindResultNotFound) Then
            Throw New System.Exception("vsFindResultNotFound")
        End If
        DTE.ExecuteCommand("Edit.SelectToLastGoBack")
        DTE.ActiveDocument.Selection.Delete()
        DTE.ActiveDocument.Selection.DeleteLeft(4)
    Loop
    MsgBox("Done")
End Sub
Brian Leeming
  • 11,540
  • 8
  • 32
  • 52