Skip to content

Instantly share code, notes, and snippets.

@giftig
Created August 25, 2017 17:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giftig/3a1d37d39c50be54c5923560fa706e54 to your computer and use it in GitHub Desktop.
Save giftig/3a1d37d39c50be54c5923560fa706e54 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2.7
import codecs
import sys
from xml.dom import minidom
filename = '/dev/stdin'
if len(sys.argv) > 1:
filename = sys.argv[1]
formatted = minidom.parse(filename).toprettyxml(indent=' ')
# Remove blank lines and trailing whitespace
lines = [
l.rstrip() for l in formatted.split('\n') if l.strip()
]
formatted = '\n'.join(lines)
print formatted.encode('utf-8')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment