Formatting XML and other stuff in VS
Customer question from DevConnections conference:
I have XML that spits out into one line in a text file - when I view it in Internet Explorer it shows all indented, when I edit in Visual Studio it's all one line. How can I use Visual Studio to indent like Internet Explorer?
Unfortunately I thought of the answer to this just after my friend from both the PDC and DevConnections conference left. The way I would probably handle the situation is to use the Format Document command in Visual Studio to automatically add the newlines to your XML.
Take this XML snippit for example:
<xml><tag1><tag2/></tag1></xml>
If I have this in an XML file in Visual Studio 2005, I can use the Edit->Advanced->Format Document (Ctrl-K Ctrl-D) to change it to
<xml>
<tag1>
<tag2/>
</tag1>
</xml>
Note this menu command as well as it's Format Selection (Ctrl-K, Ctrl-F) partner are really handy when you change some sort of formatting option in Tools->Options (like changing tabs to spaces or how you prefer to do new lines after your braces.)
Anyways I thought I'd post on the off chance you're out there somewhere following the blog!
Comments
- Anonymous
November 10, 2005
Format document works well. We also do this programmatically - we indent generated XML files in our debug builds using code like this:
XmlWriterSettings Settings = new XmlWriterSettings();
#if DEBUG
Settings.Indent = true;
Settings.IndentChars = "t";
#endif