I am generating an XML document in Python using an ElementTree, but the tostring function doesn\'t include an XML declaration when converting to plaintext.
tostring
The minimal working example with ElementTree package usage:
ElementTree
import xml.etree.ElementTree as ET document = ET.Element('outer') node = ET.SubElement(document, 'inner') node.text = '1' res = ET.tostring(document, encoding='utf8', method='xml').decode() print(res)
the output is:
1