Skip to content

Instantly share code, notes, and snippets.

@rspivak
Last active December 12, 2022 15:37
Show Gist options
  • Save rspivak/74a08170a2a04a344161 to your computer and use it in GitHub Desktop.
Save rspivak/74a08170a2a04a344161 to your computer and use it in GitHub Desktop.
Pretty print XML with lxml - one liner
$ alias ppxml='python -c "import sys,StringIO;from lxml import etree;print(etree.tostring(etree.parse(StringIO.StringIO(sys.stdin.read()), etree.XMLParser(remove_blank_text=True)), pretty_print=True))"'
@dhumanity
Copy link

I've updated your one liner to python3

alias ppxml='python3 -c "import sys, io;from lxml import etree;print(etree.tostring(etree.parse(io.StringIO(sys.stdin.read()),etree.XMLParser(remove_blank_text = True)), pretty_print = True).decode(\"utf-8\"))"'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment