我是python编程的新手,我正在将indu元素从xml文件获取到dict中
我能够解析文件并获得输出。通过代码输出的文件如下:
代码如下:
for ind_list in reflist:
for i in ind_list.attributes.keys():
print(ind_list.attributes[i].name)
print(ind_list.attributes[i].value)
name
sankar
title
student
age
25
user_2
2012-05-08
user_3
2012-05-08
name
sankar
title
student
age
25
user_1
2012-05-08
user_2
2012-05-08
name
sankar
title
student
age
25
user_4
2012-05-08
user_5
2012-05-08
目前的问题如下: 1) 我想把这些元素插入字典。我想动态地插入它。 2) 从输出中可以看出,xml文件的每一行都是不同的。如何在dict中动态添加一个键,而不是在它已经存在时添加它?你知道吗
我希望这些单独的值将其插入到数据库中。我以前在dict中使用过数据库编码。所以我可以给那部分编代码。你知道吗
您应该使用xmltodict,然后从xmltodict文档
相关问题 更多 >
编程相关推荐