用python转换xml文档

2024-10-03 13:30:29 发布

您现在位置:Python中文网/ 问答频道 /正文

好吧,我有一个大的xml文档要解析出来,这样我就可以把它们添加到数据库中。在

fileIn = open(path + 'POTS_Table'+ date + '.xml', 'r') ## gets file from location
file = fileIn.read() ## reads all data in file and saves as variable file
parser = etree.XMLParser(recover=True) ## to help with broken xml attributes
tree= etree.parse(fileIn, parser=parser) 

只要我打印结果,这个工作就很好,但是当我尝试

^{pr2}$

我得到这个错误

File "./sqltest.py", line 1932, in <module>
    main(path,date)
File "./sqltest.py", line 1912, in main
    addPots(path,date)     
File "./sqltest.py", line 1330, in addPots
     tree = ET.fromstring(file, parser=parser) ## parses the information in the XML file   , parser=parser
 TypeError: XML() got an unexpected keyword argument 'parser'

有人能帮我吗?在


Tags: pathinpytreeparserdatemainline
1条回答
网友
1楼 · 发布于 2024-10-03 13:30:29

ET.fromstring的文档没有提到解析器属性,这是您的错误告诉您的(甚至给出了行号)。在

但是,您的代码在很多其他方面似乎有点混乱。我建议您花更多的时间研究python文档。例如,我不确定parameters ={treeAttributesDictionary}应该做什么。在

相关问题 更多 >