Skip to content

Instantly share code, notes, and snippets.

@Devligue
Created March 30, 2017 11:06
Show Gist options
  • Save Devligue/8dce90656e4b3729d96764e25c2bd59e to your computer and use it in GitHub Desktop.
Save Devligue/8dce90656e4b3729d96764e25c2bd59e to your computer and use it in GitHub Desktop.
print xml in a redable way
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