appending data to an xml file
peter at engcorp.com
Tue Jan 11 21:25:01 EST 2005
Thomas Heller wrote:
> I want to append/insert additional data to an xml file.
> Better, imo, would be to add the dumped info into a proper xml tag, and
> inject it into the original file. Is that (efficiently) possible?
My technique, when I can't just strip the root element and
have a document fragment consisting of a huge list of the
other elements, is just to seek to the end of the file,
back up to the beginning of the '</xml>', and begin overwriting
the file from that point... seems to work nicely, and in
most cases since I'm the one who wrote the file in the first
place I know that I've written '</xml>\n' and can just
seek to the end minus 8 bytes (when on Windows, anyway...).
More information about the Python-list