我想使用xmltoDic加载并解析xml文件并将其添加到python列表中
我的python文件
import xmltodict
with open('input.xml') as fd:
my_dict= xmltodict.parse(fd.read())
entries = my_dict['Drivetrain']['Element']
elements=[]
for k in entries:
print(type(k))
#elements.append(k['@name'])
#print(elements)
我的xml文件
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Drivetrain>
<Element name="PowerUnit">
<Element name="Transmission">
<Element name="TX1">
</Element>
<Element name="TX2">
</Element>
</Element>
<Element name="Engine">
<Element name="V4">
</Element>
<Element name="V6">
</Element>
</Element>
</Element>
</Drivetrain>
显示python列表输出