I\'m trying to create XML using the ElementTree object structure in python. It all works very well except when it comes to processing instructions. I can create a PI easil
f = open('D:\Python\XML\test.xml', 'r+')
old = f.read()
f.seek(44,0) #place cursor after xml declaration
f.write(''+ old[44:])
I was facing the same problem and came up with this crude solution after failing to insert the PI into the .xml file correctly even after using one of the Element methods in my case root.insert (0, PI)
and trying multiple ways to cut and paste the inserted PI to the correct location only to find the data to be deleted from unexpected locations.