New submission from towb: This generates an XML declaration:
import xml.etree.ElementTree as ET root = ET.Element('rss', version='2.0') tree = ET.ElementTree(root) tree.write('test.xml', encoding='iso-8859-1', xml_declaration=True) However the declaration disappears if your don't pass an encoding. This doesn't match the documentation: xml_declaration controls if an XML declaration should be added to the file. Use False for never, True for always, None for only if not US-ASCII or UTF-8 or Unicode (default is None). ---------- components: Library (Lib) messages: 229238 nosy: towb priority: normal severity: normal status: open title: ElementTree only writes declaration when passed encoding type: behavior versions: Python 3.4 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue22622> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com