Format XML with TextWrangler

10 June, 2010 | Cristi | 2 Comments

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.

Share and Enjoy:
  • del.icio.us
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • Ma.gnolia
  • NewsVine
  • Reddit
  • Shadows
  • Simpy
  • YahooMyWeb
  • Digg
  • Facebook
  • Pownce
  • StumbleUpon
2 Comments
  1. Kevin Maes says:

    probably a typo, but it should be:
    XMLLINT_INDENT=$’\t’
    otherwise you’ll get a lot of t’s :)

  2. Cristi says:

    yeap, it’s true. Thanks. I’ve edited the post.

Leave a Reply

We love to hear your views.