def xml_out(routing, dest, use_access=False, modified_after=None, stylesheet=None, indent=True): xrouting = _xmlwrap.xml_Routing() _xmldoc_out(xrouting, routing, use_access, 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(xrouting._element) ET.ElementTree(xrouting._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 xrouting = _xmlwrap.xml_Routing(root) _xmldoc_in(xrouting, self.__routing, self.__use_access)
def xml_out(routing, dest, use_access=False, modified_after=None, stylesheet=None, indent=True): xrouting = _xmlwrap.xml_Routing() _xmldoc_out(xrouting, routing, use_access, 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 is not None: fd.write('<?xml-stylesheet type="application/xml" href="%s"?>\n' % \ (stylesheet,)) if indent is True: _indent(xrouting._element) ET.ElementTree(xrouting._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 xrouting = _xmlwrap.xml_Routing(root) _xmldoc_in(xrouting, self.__routing, self.__use_access)
def xml_in(routing, src, use_access=False): doc = ET.parse(src) root = doc.getroot() if root.tag != _root_tag: raise DBError, "unrecognized root element: " + root.tag xrouting = _xmlwrap.xml_Routing(root) _xmldoc_in(xrouting, routing, use_access)
def xml_in(routing, src, use_access=False): doc = ET.parse(src) root = doc.getroot() if root.tag != _root_tag: raise DBError, "unrecognized root element: " + root.tag xrouting = _xmlwrap.xml_Routing(root) _xmldoc_in(xrouting, routing, use_access)