def get_xml(self): f = BytesIO() tree = ET.ElementTree(self.root) tree.write(f, encoding='windows-1251', xml_declaration=True) return f.getvalue()