Create a gist now

Instantly share code, notes, and snippets.

@rspivak /ppxml
Created May 12, 2014

What would you like to do?
Pretty print XML with lxml
#!/usr/bin/env python
import sys
import StringIO
from lxml import etree
def main():
xml_text =
parser = etree.XMLParser(remove_blank_text=True)
file_obj = StringIO.StringIO(xml_text)
tree = etree.parse(file_obj, parser)
print(etree.tostring(tree, pretty_print=True))
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment