import xml.etree.ElementTree as ET import csv tree = ET.parse('data.xml') root = tree.getroot() with open('data.csv', 'wb') as csvfile: spamwriter = csv.writer(csvfile) for neighbor in root.iter('DATI'): parent = neighbor.attrib.get("ISTANTE") temp = "" for child in neighbor: temp = temp + child.text + "," temp = temp[:-1] spamwriter.writerow([parent, temp])