-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathXMLtoCSV.py
More file actions
23 lines (18 loc) · 713 Bytes
/
XMLtoCSV.py
File metadata and controls
23 lines (18 loc) · 713 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import xml.etree.cElementTree as ET
import csv
def convert(input_file, output_file):
tree = ET.parse(input_file)
root = tree.getroot()
with open(output_file, 'w+', encoding='UTF-8') as csv_file:
writer = csv.writer(csv_file)
# First element in root is the Locale info
locale = root[0].text
writer.writerow([locale])
# Write a header
writer.writerow([])
writer.writerow(["Term", "Translation"])
# Every element after should be a term-translation pair
for child in root[1:]:
term = child.attrib.get('key')
translation = child.text if child.text else ''
writer.writerow([term, translation])