def _process_xml_element(self, xml_element): """Process an xml_element. """ for i_elem in xml_element: self._tag = clean_tag(i_elem.tag) if self._tag2process.has_key(self._tag): a_process = self._tag2process[self._tag] a_process(i_elem)
def process_xml_file(self, root, name): # read the xml file and process Bag Compact addresses xml_file = self._file_from(root, name) print "Verwerk bestand: " + xml_file an_iterator = ET.iterparse(xml_file, events=("start", "end")) # get the root element.. event, self._root = an_iterator.next() for event, elem in an_iterator: if event == "end": tag = clean_tag(elem.tag) if tag == "antwoord": self._process_xml_element(elem) self._conn.commit()
def _process_LVC_product(self, elem): basis_object = None for i_elem in elem: tag = clean_tag(i_elem.tag) if basis_object is None: if bag.basis_objects.has_key(tag): basis_object = bag.basis_objects[tag] basis_object.init_values() basis_object.process(i_elem) if basis_object.is_active(): sql = basis_object.as_sql() try: self._cur.execute(sql) except dbapi2.IntegrityError: # objects with unique ids are encountered more often in # xml files delivered. Just ignore.. pass self._xml_object_count += 1 i_elem.clear() if self._xml_object_count % 100 is 0: self._root.clear()