PyDocs

Nav

Structured Markup Processing Tools

tostring

  • tostring(element, encoding='us-ascii', method='xml', *, xml_declaration=None, default_namespace=None, short_empty_elements=True)
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 optional output which
can be one of "xml" (default), "html", "text" or "c14n",
*default_namespace* sets the default XML namespace (for "xmlns").

Returns an (optionally) encoded string containing the XML data.
Changed in 3.4, 3.8
  • 3.4: Added the short_empty_elements parameter.
  • 3.8: Added the xml_declaration and default_namespace parameters.
  • 3.8: The tostring() function now preserves the attribute order specified by the user.
0 Examples
No examples for xml.etree.ElementTree/tostring.
See Also
No see-alsos for xml.etree.ElementTree/tostring
0 Notes
No notes for tostring