Generate string representation of XML element. All subelements are included. If encoding is "unicode", a string is returned. Otherwise a bytestring is returned. *element* is an Element instance, *encoding* is an optional output encoding defaulting to US-ASCII, *method* is an
(element, encoding=None, method=None, *,
xml_declaration=None, default_namespace=None,
short_empty_elements=True)
| 1080 | # -------------------------------------------------------------------- |
| 1081 | |
| 1082 | def tostring(element, encoding=None, method=None, *, |
| 1083 | xml_declaration=None, default_namespace=None, |
| 1084 | short_empty_elements=True): |
| 1085 | """Generate string representation of XML element. |
| 1086 | |
| 1087 | All subelements are included. If encoding is "unicode", a string |
| 1088 | is returned. Otherwise a bytestring is returned. |
| 1089 | |
| 1090 | *element* is an Element instance, *encoding* is an optional output |
| 1091 | encoding defaulting to US-ASCII, *method* is an optional output which can |
| 1092 | be one of "xml" (default), "html", "text" or "c14n", *default_namespace* |
| 1093 | sets the default XML namespace (for "xmlns"). |
| 1094 | |
| 1095 | Returns an (optionally) encoded string containing the XML data. |
| 1096 | |
| 1097 | """ |
| 1098 | stream = io.StringIO() if encoding == 'unicode' else io.BytesIO() |
| 1099 | ElementTree(element).write(stream, encoding, |
| 1100 | xml_declaration=xml_declaration, |
| 1101 | default_namespace=default_namespace, |
| 1102 | method=method, |
| 1103 | short_empty_elements=short_empty_elements) |
| 1104 | return stream.getvalue() |
| 1105 | |
| 1106 | class _ListDataStream(io.BufferedIOBase): |
| 1107 | """An auxiliary stream accumulating into a list reference.""" |
nothing calls this directly
no test coverage detected