Example #1
0
    def tostring(self):

        class dummy:
            pass
        xml_dataL = []
        if self.xml_header:
            xml_dataL = [self.xml_header + '\n']

        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)

        return "".join(xml_dataL)
Example #2
0
    def tostring(self):
        class dummy:
            pass

        xml_dataL = []
        if self.xml_header:
            xml_dataL = [self.xml_header + '\n']

        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)

        return "".join(xml_dataL)