title: Loading a Skeleton XML Tree with Data Using lxml
body: <p>I'm attempting to call saxify repeatedly in order to load data into an existing xml document:</p>
  <pre><code>#Must use the imports as shown below or you'll
  #get an Attribute Error!!!
  import lxml, lxml.sax
  from SaxEventReceiver import SaxEventReceiver
  import lxml.etree
  import lxml.sax
  from lxml.sax import ElementTreeProducer
  import time
  
  class Parser_Driver():
      def __init__(self):
          self.working_dir = &quot;F:\\SCRATCH\\Joseph\\Google_Project\\&quot;
          self.input_file = self.working_dir + 'August_16_Tree_Short.xml'
          self.parser = lxml.etree.XMLParser(strip_cdata=False,huge_tree=True)
          self.tree = lxml.etree.parse(self.input_file,self.parser)
          self.root = self.tree.getroot()
          self.handler = SaxEventReceiver()
          self.saxEventGenerator = lxml.sax.ElementTreeProducer(self.tree,self.handler)
  
      def Start(self):
          self.saxEventGenerator.saxify()
  
      def Print(self):
          new_tree = self.handler.etch.etree
          timestr = time.strftime(&quot;%Y%m%d-%H%M%S&quot;)
          tmp_fn = 'TreeFromContentHandler' + timestr + '.xml'
          new_tree.write(open(self.working_dir + tmp_fn, 'bw'))
  
  if __name__ == &quot;__main__&quot;:
      ad = Parser_Driver()
      ad.Start()
      ad.Start() #This call will generate the error
      a = 2
  </code></pre>
  <p>Here's where I'm catching the xml events to insert data:</p>
  <pre><code>from ast import Add
  from lib2to3.pytree import Node
  from lxml.etree import ElementTree, SubElement 
  from lxml.sax import ElementTreeContentHandler
  
  class SaxEventReceiver(ElementTreeContentHandler):
      def __init__(self):
          self.text = None
          self._element_stack = []
          self.etch = ElementTreeContentHandler()
          self._root = self.etch.etree.getroot()
      
      def startElementNS(self, name, qname, attributes):
          self.tmp_name = name
          self.tmp_qname = qname
          self.tmp_attributes = attributes
          tmpDict = {}
  
          #Fails here with 2nd call to saxify. 
          #Error is Exception has occurred: IndexError
          #list index out of range        
          self.etch.startElement(qname,tmpDict)
  
      def endElementNS(self, ns_name, qname):
          localname = ns_name
          self.etch.endElement(qname)
  
      def characters(self, data):
          self.etch.characters(data)
  </code></pre>
  <p>When I try invoke saxify a second time, an exception is thrown. I'm trying to update an existing XML Document with data. I realize the gap of my ignorance. But if anyone can help, I would appreciate it...</p>