convert xml document with python

298 views Asked by At

ok i have a big xml document to parse out so i can add them into a database.

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) 

this works fine as long as i'm printing the results, but when i try to

parameters ={treeAttributesDictionary}
update= '''update table set column1:parameters1 '''
change=update.format(**parameters)
c.execute(change)

i get this error

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'

Can any one help me?

1

There are 1 answers

1
kazagistar On

The documentation for ET.fromstring does not mention a parser attribute, which is what your error told you (and even gave you the line number).

However, your code seems to be a bit of a mess in a lot of other ways. I recommend you spend some more time studying the python documentation in general. For example, I am not sure what parameters ={treeAttributesDictionary} is supposed to do.