-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxml3.py
More file actions
67 lines (56 loc) · 1.86 KB
/
Copy pathxml3.py
File metadata and controls
67 lines (56 loc) · 1.86 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding: utf-8 -*-
"""
Created on Fri Feb 15 11:44:26 2019
@author: hejia
"""
import pandas as pd
import xml.etree.ElementTree as ET
col_names=['investmentVehicle_ID',
'FundShareClass_ID',
'Fund_ID',
'Fund',
'HistoricalPerformance',
'OperationHistory',
'BestFitIndex']
collection=pd.DataFrame(columns = col_names)
tree=ET.parse('xml_data.xml')
root=tree.getroot()
for child1 in root:
print('----------------------')
print(child1.tag,child1.attrib)
print('begin of child2')
for child2 in child1:
print(child2.tag,child2.attrib)
print('begin of child 3')
for child3 in child2:
print(child3.tag,child3.attrib)
print('begin of child 4')
for child4 in child3:
print(child4.tag,child4.attrib)
print('begin of child 5')
for child5 in child4:
print(child5.tag,child5.attrib)
record=0
for investment in root.iter('InvestmentVehicle'):
print(investment)
#d={}
#id_information=investment.attrib
#d['investmentVehicle_ID']=list(id_information.values)[0]
for investment in root.iter('InvestmentVehicle'):
investment_vehicle_ID=investment.get('_Id')
print(investment_vehicle_ID)
fund_share_class=investment.find('FundShareClass').text
print(fund_share_class)
fund_share_id=investment.find('FundShareClass').get('_Id')
print(fund_share_class)
share_share_id=investment.find('FundShareClass').get('_FundId')
print(share_share_id)
fund=investment.find('Fund').text
print(fund)
history_performance=investment.find('HistoricalPerformance').text
print(history_performance)
operation_history=investment.find('OperationHistory').text
try:
best_fit_index=investment.find('BestFitIndex').text
except:
best_fit_index=''