I’ve been using TextWrangler as default text editor in Mac for some time now and today I’ve been confronted with a small problem, I had an xml file that wasn’t formated at all and I wanted a way to easily format the file. Searched in the Text Wrangler menus and didn’t found a tidy option so I googled my problem.
As I expected, I wasn’t the first one to have this problem so I quickly found a solution. And after a minute of work I had my XML file indented and formated as I would.
So … here are the steps I did:
#!/bin/sh
xmllint --c14n "$*" | XMLLINT_INDENT=$'\t' xmllint --format -
And there you have it, now if you go to the #! menu, Unix Filters submenu you will see your Format XML.sh, click it and your xml file will be automatically formated.
A great interview with the Co-Creator of the web.