Format XML with TextWrangler
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:
- Go to your TextWrangler’s Unix Filters Folder. You can find it if you go to #! menu, Unix Filters, Open Filters Folder.
- Create a file there, paste the code below
#!/bin/sh
xmllint --c14n "$*" | XMLLINT_INDENT=$'\t' xmllint --format -
- Save the file, give it a meaningful name like “Format XML.sh” or something
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.
























31 August, 2010 at 10:19 am
probably a typo, but it should be:
XMLLINT_INDENT=$’\t’
otherwise you’ll get a lot of t’s
1 September, 2010 at 11:08 am
yeap, it’s true. Thanks. I’ve edited the post.