How to Un-format a document in Visual Studio 2008?

So there's a messy XML file where all white spaces between tags have been stripped, so it's a valid XML file but it's somewhat unreadable.

I press the magic Ctrl+K, D, and the file is beautifully formatted.

I edit it, and then I want to put it back into the compressed, hardly readable state, removing all whitespaces between the tags. How do I do that in VS 2008? I looked though the list of all available commands but couldn't find any.

Answers


Using Notepad++

I recommend you get Notepad++ and install the XML Tools plugin. The Plugins > XML Tools menu contains a Linarize XML item that does exactly what you want.

Using Visual Studio

You could do a Find & Replace using a regular expression.

First remove all the whitespace preceding any XML tags using these search criteria:

Find what: :Wh*[<] Replace with: <

Then remove all the whitespace preceding any text or attributes:

Find what: :Wh+{:Al} Replace with: \1

Note: There should be a space in front of \1.

Disclaimer: This method may not be completely accurate, so make sure to double-check the result!


The only thing I can think of is to select all the file and then keep pressing Shift+Tab until you've removed all the tabs. It won't remove all the white space though, just that at the beginning of each line.


I don't think you can come back to the original formatting if you made edits. What I would do is use emacs macros: you can do a set of keys for one line and repeat it for the whole file:

C-x ( start recording key strokes to build a keyboard macro.

C-x ) stop recording key strokes to for a keyboard macro.

then the following instruction will repeat it 200 times:

C-u 200 C-x e

(I know Visual Studio and emacs are different worlds but in some situations emacs and cygwin are the only way to go really)


A bit late to the table but you can just run two replace-bits.

  1. First press Ctrl-H while having the XML open in Visual Stuido. This will bring up replace-window. Make sure you check "Use regular expressions"-box in the replace-window
  2. Search term should contain \r\n and replace term just empty textbox without spaces. Press Replace all This will now remove all the newlines
  3. In order to remove all spaces between tags make sure replace term contains > +< (there is a space before the plus sign) and replace term >< Now press Replace all

Voila


Need Your Help

I am trying to validate phone number

javascript html regex

I am trying to validate phone number using regex, and I want to create a phone number format like this:

"An unexpected error ocurred" CRM2015 OnPremise Plugins

plugins dynamics-crm crm dynamics-crm-2015

For 2 weeks we have been experiencing a small totally random issue with plugins in CRM 2015 OnPremise. When we make an upload, randomly and without much sense (at least according to analyze all cod...