Tuesday, January 13, 2015

TextWrangler: formatting XML file

Go to directory where TextWrangle keeps all the scripts:

$ cd ~/Library/Application\ Support/TextWrangler/Text\ Filters 

Create a new file for XML formatting:

Text Filters $ touch FormatXML.sh 


This will open the new file in TextWrangler (or whatever editor you have set).
Text Filters $ edit FormatXML.sh 

Enter this text in that file and save:

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

Now you can format any XML by selecting TextWrangler menu: 

Text > Apply Text Filter > FormatXML