Created
March 30, 2017 11:06
-
-
Save Devligue/8dce90656e4b3729d96764e25c2bd59e to your computer and use it in GitHub Desktop.
print xml in a redable way
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
import xmltodict | |
xml_string = 'your_xml_string' | |
d = xmltodict.parse(xml_string) | |
def pretty(d, indent=0): | |
for key, value in d.items(): | |
print('\t' * indent + str(key)) | |
if isinstance(value, dict): | |
pretty(value, indent + 1) | |
elif isinstance(value, list): | |
for item in value: | |
print('\n') | |
pretty(item, indent + 1) | |
else: | |
print('\t' * (indent + 1) + str(value)) | |
pretty(d) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment