I have an XML file, which I would like to convert / export to a csv(-like) format.
Example:
<root>
<child>
<Name>John</Name>
<Surname>Doe</Surname>
<Name>George</Name>
<Surname>Washington</Surname>
</child>
</root>
ATM I do it like this (the print is for debug, nothing finished yet):
#!/bin/python env
import xml.etree.ElementTree as etree
tree = etree.parse('./foobar.xml')
root = tree.getroot()
elements = ('Name', 'Surname')
for i in elements:
for i in root.iter(i):
print(i.text)
Current Output:
John
George
Doe
Washington
The result I would like to get:
John, Doe
George, Washington
Can anyone give me a hand here?
Thank you very much.