Format XML in Visual Studio

Here’s an easy tip for formatting XML in Visual Studio which apparently isn’t very well known.  There are times I find myself using Visual Studio to view/edit an XML file, and the source XML is tightened with no line breaks (for whatever reason) after the nodes.  Below is one example.

<?xml version="1.0"?>
<BrowserInfo><Browser><Name>Microsoft Internet Explorer</Name><Path>"C:\Program Files\Internet Explorer\iexplore.exe"</Path><Resolution>0</Resolution><IsDefault>True</IsDefault><DDE><Service>IExplore</Service><TopicOpenURL>WWW_OpenURL</TopicOpenURL><ItemOpenURL>"%s",,0xffffffff,3,,,,</ItemOpenURL><TopicActivate>WWW_Activate</TopicActivate><ItemActivate>0xffffffff,0</ItemActivate></DDE></Browser><InternalBrowser><Resolution>0</Resolution><IsDefault>False</IsDefault></InternalBrowser></BrowserInfo>

You can use the Format Document (Ctrl+E, D) command from the Edit->Advanced menu to nicely format your XML document:


This results in a much nicer formatting of the hierarchical information:

<?xml version="1.0"?>
    <Name>Microsoft Internet Explorer</Name>
    <Path>"C:\Program Files\Internet Explorer\iexplore.exe"</Path>

3 Responses to “Format XML in Visual Studio”

  1. in VS2010 command is control K-D

  2. Great tip, thanks for posting. The simple tips are often the best.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: