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″?> <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>