Last active
August 19, 2019 02:47
-
-
Save python012/a2426c535d136e5c345be700b4ee4310 to your computer and use it in GitHub Desktop.
pretty print xml node, work well with Chinese xml doc
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
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