0

我想要一个 Visual Studio 宏来删除给定 XML 文件中的所有注释。例如,鉴于此:

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

我想得到这个:

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

<config>

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

我搜索了执行此操作的编辑器和 VS 宏,但找不到任何东西。

4

1 回答 1

0

我自己写了:

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
于 2012-09-07T14:00:06.367 回答