format xml, pretty print

Thufir picture Thufir · Nov 9, 2010 · Viewed 8.7k times · Source

I know of two ways to "pretty print", or format, xml:

  1. shell tools
  2. Hack 38 Pretty-Print XML Using a Generic Identity Stylesheet and Xalan

what other free (as in beer) formatters are there? (aside from using javascript)

Answer

Nic Gibson picture Nic Gibson · Nov 9, 2010

Well, the identity transform you linked to is portable to any XSLT processor (Saxon, msxml, etc).

Additionally, you could look at xmllint which is part of the LibXML2 toolkit. The --format option allows you to pretty print the input. Similar functionality exists in XMLStarlet (which uses LibXML2 under the hood iirc).