Pretty print XML on Linux Command Line BASH

It’s quite handy to indent XML when you need to read it with the human eye, but on a terminal it’s often not as easily readible.

Fortunatly there’s a command which’ll indent it so you can actually read it;

xmllint –format file.xml

This will show you how ugly it could be:

 

Screenshot Unformatted XML on terminal
Screenshot Unformatted XML on terminal

 

And behold the indented beauty of this little gem:

Screenshot indented XML on terminal
Screenshot indented XML on terminal
Advertisements

5 thoughts on “Pretty print XML on Linux Command Line BASH

    1. Hi Mohit,

      Not that i know of. The easiest way to get colored output is to copy the formatted XML to an editor and copy the colored output from there. For a couple of suggestions look for “colored xml formatting” on Google. (Also plenty of free options available)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s