Created
December 3, 2012 01:04
-
-
Save t2y/4191973 to your computer and use it in GitHub Desktop.
python 1 liner for xml pretty print with standard input
This file contains 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
$ cat sample.xml | python -c "import sys; from xml.dom.minidom import parse; print parse(sys.stdin).toprettyxml(indent=' ')" |
To avoid empty lines:
python3 -c "import sys; from xml.dom.minidom import parse; print('\n'.join([line for line in parse(sys.stdin).toprettyxml().split('\n') if line.strip()]))"
ref: https://stackoverflow.com/questions/14479656/empty-lines-while-using-minidom-toprettyxml
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
or for python3:
python -c "import sys; from xml.dom.minidom import parse; print(parse(sys.stdin).toprettyxml(indent=' '))"