Formatting XML from command line

Ever had to work with not properly formatted XML file? Like, where all its elements were just stacked in one single line? It doesn't make any real difference to XML reading libraries, but trying to read such XML yourself becomes huge pain. As it turns out, solution to this is pretty simple.

Ever had to work with not properly formatted XML file? Like, where all its elements were just stacked in one single line?

It doesn't make any real difference to XML reading libraries, but trying to read such XML yourself becomes huge pain.

As it turns out, solution to this is pretty simple - xmllint command line tool.

xmllint --format original.xml > formatted.xml

If you don't have xmllint installed yet:

sudo apt-get install libxml2-utils