title: How to write XML declaration using xml.etree.ElementTree
body: <p>I am generating an XML document in Python using an <a href="https://docs.python.org/2/library/xml.etree.elementtree.html" rel="noreferrer"><code>ElementTree</code></a>, but the <code>tostring</code> function doesn't include an <a href="http://xmlwriter.net/xml_guide/xml_declaration.shtml" rel="noreferrer">XML declaration</a> when converting to plaintext.</p>
  
  <pre class="lang-python prettyprint-override"><code>from xml.etree.ElementTree import Element, tostring
  
  document = Element('outer')
  node = SubElement(document, 'inner')
  node.NewValue = 1
  print tostring(document)  # Outputs "&lt;outer&gt;&lt;inner /&gt;&lt;/outer&gt;"
  </code></pre>
  
  <p>I need my string to include the following XML declaration:</p>
  
  
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes" ?&gt;
  </code></pre>
  
  <p>However, there does not seem to be any documented way of doing this.</p>
  
  <p>Is there a proper method for rendering the XML declaration in an <code>ElementTree</code>?</p>