I'm learning Python and need your help.
I'm trying to parse an XML file to TSV using minidom. In that XML file I have multiple tags with same name. I want concatenate them and return in a single delimited string. Can anyone help me.
XML:
<items>
<item_name>iPhone</item_name>
<category>Smart Phone</category>
<category>Electronics</category>
<category>Communications</category>
</items>
Desired output:
iPhone Smart Phone, Electronics, Communications
Python Code:
dom = parseString(data)
xmlTag = dom.getElementsByTagName('items')
for node in xmlTag:
item = node.getElementsByTagName('item')[0]
cat = node.getElementsByTagBane('category')
print("%s\t%s" % item, cat)
node.getElementsByTagBane(). Furthermore, the selection of elements with tag name'item'will be empty because the xml you provided simply contains no element of that name. Please correct your code.