title: Node.toprettyxml() adds newlines to DOCTYPE in Python
body: <p>When using <code>prettify</code> my DOCTYPE is broken into three lines. How can I keep it on one line?</p>
  
  <p>The "broken" output:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!DOCTYPE smil
    PUBLIC '-//W3C//DTD SMIL 2.0//EN'
    'http://www.w3.org/2001/SMIL20/SMIL20.dtd'&gt;
  &lt;smil xmlns="http://www.w3.org/2001/SMIL20/Language"&gt;
    &lt;head&gt;
      &lt;meta base="rtmp://cp23636.edgefcs.net/ondemand"/&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;switch&gt;
        &lt;video src="mp4:soundcheck/1/clay_aiken/02_sc_ca_sorry_256.mp4" system-bitrate="336000"/&gt;
        &lt;video src="mp4:soundcheck/1/clay_aiken/02_sc_ca_sorry_512.mp4" system-bitrate="592000"/&gt;
        &lt;video src="mp4:soundcheck/1/clay_aiken/02_sc_ca_sorry_768.mp4" system-bitrate="848000"/&gt;
        &lt;video src="mp4:soundcheck/1/clay_aiken/02_sc_ca_sorry_1128.mp4" system-bitrate="1208000"/&gt;
      &lt;/switch&gt;
    &lt;/body&gt;
  &lt;/smil&gt;
  </code></pre>
  
  <p>The script:</p>
  
  <pre class="lang-python prettyprint-override"><code>import csv
  import sys
  import os.path
  
  from xml.etree import ElementTree
  from xml.etree.ElementTree import Element, SubElement, Comment, tostring
  
  from xml.dom import minidom
  
  def prettify(doctype, elem):
      """Return a pretty-printed XML string for the Element.
      """
      rough_string = doctype + ElementTree.tostring(elem, 'utf-8')
      reparsed = minidom.parseString(rough_string)
      return reparsed.toprettyxml(indent="  ", encoding = 'utf-8')
  
  doctype = '&lt;!DOCTYPE smil PUBLIC "-//W3C//DTD SMIL 2.0//EN" "http://www.w3.org/2001/SMIL20/SMIL20.dtd"&gt;'
  
  video_data = ((256, 336000),
                (512, 592000),
                (768, 848000),
                (1128, 1208000))
  
  
  with open(sys.argv[1], 'rU') as f:
      reader = csv.DictReader(f)
      for row in reader:
          root = Element('smil')
          root.set('xmlns', 'http://www.w3.org/2001/SMIL20/Language')
          head = SubElement(root, 'head')
          meta = SubElement(head, 'meta base="rtmp://cp23636.edgefcs.net/ondemand"')
          body = SubElement(root, 'body')
  
          switch_tag = ElementTree.SubElement(body, 'switch')
  
          for suffix, bitrate in video_data:
              attrs = {'src': ("mp4:soundcheck/{year}/{id}/{file_root_name}_{suffix}.mp4"
                               .format(suffix=str(suffix), **row)),
                       'system-bitrate': str(bitrate),
                       }
              ElementTree.SubElement(switch_tag, 'video', attrs)
  
          file_root_name = row["file_root_name"]
          year = row["year"]
          id = row["id"]
          path = year+'-'+id
  
          file_name = row['file_root_name']+'.smil'
          full_path = os.path.join(path, file_name)
          output = open(full_path, 'w')
          output.write(prettify(doctype, root))
  </code></pre>