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