forked from roytuts/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxml-csv.py
More file actions
33 lines (26 loc) · 1.76 KB
/
xml-csv.py
File metadata and controls
33 lines (26 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from xml.etree import ElementTree
tree = ElementTree.parse('input.xml')
root = tree.getroot()
data = []
for policy in root:
policyId = policy.find('policyId').text
statecode = policy.find('statecode').text
eq_site_limit = policy.find('eq_site_limit').text
hu_site_limit = policy.find('hu_site_limit').text
fl_site_limit = policy.find('fl_site_limit').text
fr_site_limit = policy.find('fr_site_limit').text
tiv_2011 = policy.find('tiv_2011').text
tiv_2012 = policy.find('tiv_2012').text
eq_site_deductible = policy.find('eq_site_deductible').text
hu_site_deductible = policy.find('hu_site_deductible').text
fl_site_deductible = policy.find('fl_site_deductible').text
fr_site_deductible = policy.find('fr_site_deductible').text
point_latitude = policy.find('point_latitude').text
point_longitude = policy.find('point_longitude').text
line = policy.find('line').text
construction = policy.find('construction').text
point_granularity = policy.find('point_granularity').text
#print('{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}'.format(policyId, statecode, eq_site_limit, hu_site_limit, fl_site_limit, fr_site_limit, tiv_2011, tiv_2012, eq_site_deductible, hu_site_deductible, fl_site_deductible, fr_site_deductible, point_latitude, point_longitude, line, construction, point_granularity))
data.append('{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}'.format(policyId, statecode, eq_site_limit, hu_site_limit, fl_site_limit, fr_site_limit, tiv_2011, tiv_2012, eq_site_deductible, hu_site_deductible, fl_site_deductible, fr_site_deductible, point_latitude, point_longitude, line, construction, point_granularity))
print (data)
#with open('output.csv', 'w') as f: f.write('\n'.join([row for row in data[1:]]))