Thursday, December 17, 2009

Pretty Printing XML on Windows.

It happens to the best of us, we get some ugly XML string with no formatting, and we need to view it, ideally in a formatted fashion. XMLLint is the answer. Ugly XML is the input, nicely formatted XML is the output. Finding a version of XMLLint for windows was a challenge till I found this project: http://code.google.com/p/xmllint. Unfortunately this xmllint requires an xml filename as input, and I wanted a version that takes xml on stdin, and produces pretty xml on stdout(*). Luckily this project had source code available and the pretty printing is trivial, here's the full code listing for 'my version' of XMLLint:



Example Usage(+):









NOTES:

(*) StdIn -> Filter -> StdOut is a common trick for VI folks. the syntax is: :%!

(+) Any guesses why I needed a screen shot for example usage?

0 comments:

Post a Comment