A simple four line function for converting a dictionary into a simple xml string.
| Python |
1 2 3 4 5 | def dict2xml(dict, xml = ''):
for key,value in dict.iteritems():
exec 'content = '+ {'str': 'value', 'dict': 'dict2xml(value)'}[type(value).__name__]
xml += '<%s>%s</%s>' % (key, str(content), key)
return xml
|


Comments
It doesn't work for me, even with simple cases:
Using exec has really many problems (security, speed, ...) and it's not required here at all.
Sign in to comment