Reformat XML in Visual Studio 2010

Visual StudioVisual Studio-2010

Visual Studio Problem Overview


Is there an easy way to reformat an XML file while viewing it Visual Studio 2010. For example, if you open a generated app.config file, it might look like:

<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

This is difficult to read, is there a way to instruct Visual Studio 2010 to format this, so that it looks more like:

<?xml version="1.0"?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

Thanks for any help.

Update: With credit to Julien Hoarau for one of the answers. The answers are:

Edit -> Advanced -> Format Document (Ctrl+K, Ctrl+D)
Edit -> Advanced -> Format Selection (Ctrl+K, Ctrl+F)

Visual Studio Solutions


Solution 1 - Visual Studio

Yes you can :

Edit > Advanced > Format document (Ctrl+K Ctrl+D)

Solution 2 - Visual Studio

If you want to leave your right hand free to do something else, you can use Ctrl+E, Ctrl+D.

Not sure how this is different from Ctrl+K, Ctrl+D.

Solution 3 - Visual Studio

Not 100% sure about VS2010, but in VS2015 if you copy and paste a long string of XML into an .XML document, it will automatically reformat it.

("Format Document" is usually the way to go, just mentioning another option.)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMichael GoldshteynView Question on Stackoverflow
Solution 1 - Visual StudioJulien HoarauView Answer on Stackoverflow
Solution 2 - Visual StudioPaul SpangleView Answer on Stackoverflow
Solution 3 - Visual StudioJemmehView Answer on Stackoverflow