1

I use ElementTree as a my python xml util. But recently I had a problem in a time to write it. In my code, it gather about a 10MB data and write it end of the code. So it takes around 10 to 12 seconds. But within progress, writing progress take about 8 to 10 seconds.
I hope to change my code to save time. As a normal file write code, is there any library it works in a non-linear manner?

Added

Usually I write like below

from xml.etree.cElementTree import Element, ElementTree
rootEm = Element("root")
childEm1 = Element("child1")
rootEm.append(childEm1)
childEm2 = Element("child2")
rootEm.append(childEm2)
ElementTree(rootEm).write(filename)        ## I always save it at the last time of process

But I want work like this

import SOMEXMLWRITER
_f = open(filename, "w")                   ## open file first
writer = SOMEXMLWRITER(_f)
rootEm = Element("root")                   ## add Element at that time
writer.addXMLDocument(rootEm)
childEm1 = Element("child1")
rootEm.append(childEm1)
childEm2 = Element("child2")
rootEm.append(childEm2)
_f.close()                                 ## just close file... DONE!
Hyun-geun Kim
  • 919
  • 3
  • 22
  • 37
  • Also see, might be related: [Non-Blocking method for parsing (streaming) XML in python](http://stackoverflow.com/questions/1459648/non-blocking-method-for-parsing-streaming-xml-in-python) and [How can I process xml asynchronously in python?](http://stackoverflow.com/questions/2090096/how-can-i-process-xml-asynchronously-in-python). – alecxe Nov 27 '14 at 02:02
  • @alecxe I added a sample to explain my purpose. – Hyun-geun Kim Nov 27 '14 at 06:54

0 Answers0