I have an etree object called projectxml:
projetxml type <type 'lxml.etree._Element'>
I need to save it to disk, so I convert it to an element tree:
savedxml=et.ElementTree(projetxml)
savedxml.write('/home/simon/Vysis.xml')
Another script was supposed to load the Vysis.xml file and two other files of the same type:
vysis=et.parse('/home/simon/Vysis.xml')
asi=et.parse('/home/simon/ASI.xml')
psi=et.parse('/home/simon/PSI.xml')
Now the objects asi, psi and vysis lxml are of type, for example:
<lxml.etree._ElementTree object at 0xa7eaf8c>
My problem is that I can no longer do:
R=et.Element('DataBase')
R.append(asi)
R.append(psi)
R.append(vysis)
because of a mistake:
R.append(asi)
File "lxml.etree.pyx", line 697, in lxml.etree._Element.append (src/lxml /lxml.etree.c:35471)
TypeError: Argument 'element' has incorrect type (expected lxml.etree._Element, got lxml.etree._ElementTree)
I guess I have two solutions. The first one would be to avoid converting etree.Element to etree.ElementTree and save it “directly”, but I don't know how to do it. The second solution will be the inverse conversion of the etree.ElementTree type to the etree.Element type ... Should there be a clean solution for saving / loading an xml object?
source
share