Skip to content

Instantly share code, notes, and snippets.

@python012
Last active August 19, 2019 02:47
Show Gist options
  • Save python012/a2426c535d136e5c345be700b4ee4310 to your computer and use it in GitHub Desktop.
Save python012/a2426c535d136e5c345be700b4ee4310 to your computer and use it in GitHub Desktop.
pretty print xml node, work well with Chinese xml doc
from lxml import etree
import xml.dom.minidom as mmd
xml_root = etree.parse(xml_fiel_path, etree.XMLParser())
def print_xml(xml_root):
s = etree.tostring(xml).decode('utf-8')
urgly_xml = ''.join(s.split())
good_xml = mmd.parseString(urgly_xml)
print(good_xml.toprettyxml(indent=' ',))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment