Created
December 3, 2017 06:14
-
-
Save coderfi/69798a88fe3641aa80e0ed5e39c106b2 to your computer and use it in GitHub Desktop.
Pretty prints an xml file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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