Format XML with TextWrangler – updated

– Open TextWrangler and open a new text file.
– Copy and paste the code below into this file.

#!/bin/sh
xmllint --c14n "$*" | XMLLINT_INDENT=$'\t' xmllint --encode UTF-8 --format -
– Save the file, something like TidyXML.sh, in the Filters folder. (currentUser/Library/Application Support/TextWrangler/Unix Support/Unix Filters)
– You can find the filters folder by going to the #! menu and go to the Unix Filterssub-menu, and select the Open Filters Folder, like below.
– Restart TextWrangler
– Anytime you want to format an XML file, go to this menu and select the TidyXML.sh

Updated:
TextWrangler 4 now passes either the selected text (if any) or the contents
of the entire document directly to text filters on STDIN, instead of
passing a reference to a temporary file in argv[1].

Thus, you’ll need to change the first ‘xmllint’ command to take input from
STDIN, like so:

#!/bin/sh 
xmllint --c14n - | XMLLINT_INDENT=$'\t' xmllint --encode UTF-8 --format -