def xml_out(inventory, dest, instr=0, modified_after=None, stylesheet=None, indent=True): xinventory = _xmlwrap.xml_Inventory() _xmldoc_out(xinventory, inventory, instr, modified_after) if isinstance(dest, basestring): fd = file(dest, "w") elif hasattr(dest, "write"): fd = dest else: raise TypeError, "invalid file object" try: filename = fd.name except AttributeError: filename = '<???>' fd.write('<?xml version="1.0" encoding="utf-8"?>\n') if stylesheet != None: fd.write('<?xml-stylesheet type="application/xml" href="%s"?>\n' % \ (stylesheet,)) if indent is True: _indent(xinventory._element) ET.ElementTree(xinventory._element).write(fd, encoding="utf-8") if isinstance(dest, basestring): fd.close()
def close(self): root = self.__p.close() if root.tag != _root_tag: raise DBError, "unrecognized root element: " + root.tag xinventory = _xmlwrap.xml_Inventory(root) _xmldoc_in(xinventory, self.__inventory)
def xml_in(inventory, src): doc = ET.parse(src) root = doc.getroot() if root.tag != _root_tag: raise DBError, "unrecognized root element: " + root.tag xinventory = _xmlwrap.xml_Inventory(root) _xmldoc_in(xinventory, inventory)