Say, I have the following data structure:
data = {'cheese':
[{'url': 'url a', 'phone': 'phone a', 'products': ['butter', 'cheese'], 'name': 'name a'}],
'butter':
[{'url': 'url b', 'phone': 'phone b', 'products': ['butter'], 'name': 'name b'}, {'url': 'url a', 'phone': 'phone a', 'products': ['butter', 'cheese'], 'name': 'name a'}]}
And I want to create the following xml-file based on it:
xmlTemplate = """<root>
<product>
<type>cheese</type>
<consumer>
<url>url a</url>
<phone>phone a</phone>
</consumer>
<type>butter</type>
<consumer>
<url>url a</url>
<phone>phone a</phone>
</consumer>
<consumer>
<url>url b</url>
<phone>phone b</phone>
</consumer>
</product>
</root>"""
I tried to use string formatting to create such xml, but I could not figure out because of nested list and dictionary. Does anybody know how to do this? Or maybe it's better to use some other method?
Thanks, Alex
No comments:
Post a Comment