Format and Indent XML in Ubuntu Linux

While playing with Castor, I used one of their tools to generate an XML file.
The problem is that the XML file was one line. It was pretty hard to read with the text wrapping.

Here’s how to turn ugly.xml into pretty.xml in Ubuntu Linux

Install tidy:

sudo apt-get install tidy

Parse the ugly xml with tidy:

cat ugly.xml  | tidy -utf8 -xml -w 255 -i -c -q -asxml > pretty.xml

The result is a nicely formatted and Indented XML file, where the allowed width was 255 characters.

Here’s the man page with the details on the options.

This entry was posted in XML and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

2 Comments

  1. Philler
    Posted June 9, 2010 at 6:34 pm | Permalink

    Or simple: xmllint –format ugly.xml –output pretty.xml
    without install 😉

  2. winaro
    Posted June 9, 2011 at 6:24 am | Permalink

    thanx a lot Philler !!!

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*