Convert python dictionary to xml
Recently, I needed to create a Python service that returns JSON and XML.
There is a struct in Python called dictionary (dict) that is next to JSON and already have a specific class to convert it. So, I created a dictionary structure and was already halfway there.
For XML there are another classes, but I would needed to implement the same logic again and it is a bad smell.
Searching, I found some gists of functions that convert dict to XML but they were not what I needed.
So follow the complete code that I used to create based on another gists.
References:
- Huseyin Yilmaz – Convert python dictionary to xml
- Ye Lui – dict2xml
- Reimund – Simple Dictionary XML Serializer
And you, already had similar situation? Comment it!