Quantcast
Channel: Visual Studio Integrate forum
Viewing all articles
Browse latest Browse all 4410

How to smart format xml file

$
0
0

I am creating a project template wizard which does replacement on an xml file. After the replacement, I want to format the whole xml document. Smart format is done automatically for class file (for example .cs files) but not .xml files in the project. I've tried different routes suggested in the forum:

  1. EditPoint.SmartFormat() doesn't work for XML file.
  2. DTE.ExecuteCommand("Edit.FormatDocument") fails when the document window isn't opened. (In IWizard implementation, it seems that even at RunFinished(), the project item window hasn't been completely activated so when I use this method, it throws an error)

Any workaround to do it for XML file, especially when the file hasn't been opened in Visual Studio yet?

        For Each pi As ProjectItem In DTE.Solution.Projects.Item(1).ProjectItems
            If (pi.Name.EndsWith(".xml")) Then

                If Not pi.IsOpen(Constants.vsViewKindCode) Then
                    pi.Open(Constants.vsViewKindCode).Activate()
                End If
                Dim td As TextDocument = pi.Document.Object("TextDocument")
                td.StartPoint.CreateEditPoint().SmartFormat(td.EndPoint)

                'td.Selection.SelectAll()
                'td.Selection.SmartFormat()

DTE.ExecuteCommand("Edit.FormatDocument") End If Next



Viewing all articles
Browse latest Browse all 4410

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>