Get AirVPN and be free online

Monday, December 29, 2008

How to format (prettify) XML

Today I used Eclipse with the XMLBuddy plugin to format (prettify) a chunk of XML.
I then tweaked it with TextPad... as follows.

Get Eclipse at The IDE for Java developers will probably be fine for you. (It may seem like serious overkill for formatting a bit of XML, but that all depends on how badly you want to format that bit of XML now doesn't it? :))

Get the XMLBuddy plugin:

You just need to unpack the XMLBuddy plugin ZIP file to the Eclipse "plugins" directory, but here are some XMLBuddy install tips in case you have problems:

Then just open your XML file with Eclipse and choose "Format" from the "XML" menu.

The only problem is that it uses tabs to indent the XML, which you may find a bit of a pain, so I then tweaked it in TextPad as follows:
Copy the XML you formatted in Eclipse into TextPad (or some other text editor with search&replace) and use F8 (find/replace) to swap the tabs for spaces, and you've got a decently formatted bit of XML!

Good luck :)

No comments:

eXTReMe Tracker