title: Write continuously to output file using Python lxml
body: <p>I'm writing big chunks of data from a database down to an XML file. I'm using Python and its lxml library to create the file.
  I notice that it's generating the whole XML file in memory and then outputs it to the file at the end, is there's a way to dump the xml file for every X number of database objects?</p>
  
  <pre><code>import lxml.etree as etree
  import os
  
  root = etree.Element('root')
  db_obj1 = etree.SubElement(root, 'item')
  db_obj2 = etree.SubElement(root, 'item')
  db_obj3 = etree.SubElement(root, 'item')
  et = etree.ElementTree(root)
  et.write(sys.stdout)
  </code></pre>
  
  <p>I've tried with ElemenTree().write(), but can't find any setting or best-practice on how to accomplish this in the documentation at <a href="http://lxml.de/api/lxml.etree._ElementTree-class.html" rel="nofollow">http://lxml.de/api/lxml.etree._ElementTree-class.html</a>.</p>
  
  <p>Looking to decrease the total memory footprint.</p>