Get string source of Python xml ElementTree

elementtree, python, xml

Solution

import xml.etree.ElementTree as ET
tree = ET.parse(source)
root = tree.getroot()
ET.tostring(root)

Note that there may be formatting differences between the content of `source` and `ET.tostring(doc)`.

Problem

How would you get the source of an `ElementTree` as a string in Python?

Original source