def elem_tostring(self, elem, include_ns=False, use_linebreaks=True, include_header=False): xml_dataL = [] class dummy: def write(self, sInp ): if sys.version_info < (3,): sInp = sInp.decode('utf-8') if sInp.strip().startswith(u'xmlns:') and not include_ns: return if sInp.strip().endswith(u'>') and use_linebreaks: sInp = sInp.replace('>','>\n') xml_dataL.append(sInp ) dummy_file = dummy() #dummy_file.write = xml_dataL.append dummy_file = dummy() # There are differences between the python2 and python3 serialize routines if sys.version_info < (3,): ET._serialize_xml(dummy_file.write, elem, "utf-8", self.qnameOD, self.nsOD) else: short_empty_elements = True # use short format for empty elements ET._serialize_xml(dummy_file.write, elem, self.qnameOD, self.nsOD, short_empty_elements) sOut = u"".join(xml_dataL) sOut = sOut.encode('utf-8') if include_header and self.xml_header: sOut = self.xml_header + '\n' + sOut return sOut
def tostring(self): xml_dataL = [] if self.xml_header: xml_dataL = [self.xml_header + '\n'] class dummy: pass def write(self, sInp): if sys.version_info < (3, ): sInp = sInp.decode('utf-8') xml_dataL.append(sInp) dummy_file = dummy() #dummy_file.write = xml_dataL.append # There are differences between the python2 and python3 serialize routines if sys.version_info < (3, ): ET._serialize_xml(dummy_file.write, self.root, "utf-8", self.qnameOD, self.nsOD) else: short_empty_elements = True # use short format for empty elements ET._serialize_xml(dummy_file.write, self.root, self.qnameOD, self.nsOD, short_empty_elements) sOut = "".join(xml_dataL) return sOut.encode('utf-8')
def elem_tostring(self, elem, include_ns=False, use_linebreaks=True, include_header=False): xml_dataL = [] class dummy: def write(self, sInp): if sys.version_info < (3, ): sInp = sInp.decode('utf-8') if sInp.strip().startswith('xmlns:') and not include_ns: return if sInp.strip().endswith('>') and use_linebreaks: sInp = sInp.replace('>', '>\n') xml_dataL.append(sInp) dummy_file = dummy() #dummy_file.write = xml_dataL.append dummy_file = dummy() # There are differences between the python2 and python3 serialize routines if sys.version_info < (3, ): ET._serialize_xml(dummy_file.write, elem, "utf-8", self.qnameOD, self.nsOD) else: short_empty_elements = True # use short format for empty elements ET._serialize_xml(dummy_file.write, elem, self.qnameOD, self.nsOD, short_empty_elements) sOut = "".join(xml_dataL) sOut = sOut.encode('utf-8') if include_header and self.xml_header: sOut = self.xml_header + '\n' + sOut return sOut
def tostring(self): xml_dataL = [] if self.xml_header: xml_dataL = [self.xml_header + '\n'] class dummy: pass def write(self, sInp ): if sys.version_info < (3,): sInp = sInp.decode('utf-8') xml_dataL.append(sInp ) dummy_file = dummy() #dummy_file.write = xml_dataL.append # There are differences between the python2 and python3 serialize routines if sys.version_info < (3,): ET._serialize_xml(dummy_file.write, self.root, "utf-8", self.qnameOD, self.nsOD) else: short_empty_elements = True # use short format for empty elements ET._serialize_xml(dummy_file.write, self.root, self.qnameOD, self.nsOD, short_empty_elements) sOut = u"".join(xml_dataL) return sOut.encode('utf-8')