MCPcopy Index your code
hub / github.com/python/cpython / tostring

Function tostring

Lib/xml/etree/ElementTree.py:1077–1099  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1075# --------------------------------------------------------------------
1076
1077def 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
1101class _ListDataStream(io.BufferedIOBase):
1102 """An auxiliary stream accumulating into a list reference."""

Callers

nothing calls this directly

Calls 3

ElementTreeClass · 0.85
writeMethod · 0.45
getvalueMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…