AttributeError: type object 'ElementTree' has no attribute 'tostring'
The xml.etree.ElementTree.ElementTree
class does not have a tostring
method. It is a function in the xml.etree.ElementTree
module.
You have imported tostring
from the module already in your code. Change
rough_string = ElementTree.tostring(elem, 'utf-8', method="xml", short_empty_elements=True)
to
rough_string = tostring(elem, 'utf-8', method="xml")
and it should work.
The short_empty_elements
parameter is only available in Python 3.4. It does not work in Python 2.7.
You're importing the wrong thing. tostring
is a function in the xml.etree.ElementTree
module, not a method of xml.etree.ElementTree.ElementTree
.