Skip to content

Instantly share code, notes, and snippets.

@coderfi
Created December 3, 2017 06:14
Show Gist options
  • Save coderfi/69798a88fe3641aa80e0ed5e39c106b2 to your computer and use it in GitHub Desktop.
Save coderfi/69798a88fe3641aa80e0ed5e39c106b2 to your computer and use it in GitHub Desktop.
Pretty prints an xml file
#!/usr/bin/env python
''' Pretty prints an xml file.
Usage:
python prettyxml.py [filename.xml]
or
cat filename.xml | python prettyxml.py
Author: coderfi@gmail.com
'''
from __future__ import print_function
import sys
import xml.dom.minidom
if len(sys.argv) == 1:
xml = xml.dom.minidom.parseString(sys.stdin.read())
else:
xml = xml.dom.minidom.parse(sys.argv[1])
print(xml.toprettyxml())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment