title: python xml pretty print not working
body: <p>I am changing an some xml by adding some nodes and values from a list. I can successfully create all the new tags and values, I am creating them between the contributors tags, but when I save the xml out to a new file, the tags I create are all on one line. Here is a sample of my code:</p>
  
  <pre><code>templateXml = """&lt;?xml version="1.0" encoding="utf-8" standalone="yes"?&gt;
  &lt;package&gt;
    &lt;delivery_type&gt;new&lt;/delivery_type&gt;
    &lt;feature&gt;
      &lt;feature_type&gt;Movie&lt;/feature_type&gt;
      &lt;contributors&gt;
      &lt;/contributors&gt;
  &lt;/package&gt;"""
  
  from lxml import etree
  tree = etree.fromstring(templateXml)
  
  node_video = tree.xpath('//feature/contributors')[0]
  for cast in castList:
      pageElement = etree.SubElement(node_video, 'contributor')
      node_video1 = tree.xpath('//feature/contributors/contributor')[0]
      pageElement.attrib['type'] = 'cast'
      pageElement1 = etree.SubElement(pageElement, 'name')
      pageElement1.text = cast.text
      pageElement2 = etree.SubElement(pageElement, 'role')
      pageElement2.text = "actor"
  
  xmlFileOut = '/Users/User1/Desktop/Python/Done.xml'   
  
  with open(xmlFileOut, "w") as f:
      f.write(etree.tostring(tree, pretty_print = True, xml_declaration = True, encoding='UTF-8', standalone="yes"))
  </code></pre>
  
  <p>Here is saved xml file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" standalone="yes"?&gt;
  &lt;package&gt;
    &lt;delivery_type&gt;new&lt;/delivery_type&gt;
    &lt;feature&gt;
      &lt;feature_type&gt;Movie&lt;/feature_type&gt;
      &lt;contributors&gt;
      &lt;contributor type="cast"&gt;&lt;name&gt;John Doe&lt;/name&gt;&lt;role&gt;actor&lt;/role&gt;&lt;/contributor&gt;&lt;contributor type="cast"&gt;&lt;name&gt;Another Actors name&lt;/name&gt;&lt;role&gt;actor&lt;/role&gt;&lt;/contributor&gt;&lt;contributor type="cast"&gt;&lt;name&gt;Jane Doe&lt;/name&gt;&lt;role&gt;actor&lt;/role&gt;&lt;/contributor&gt;&lt;contributor type="cast"&gt;&lt;name&gt;John Smith&lt;/name&gt;&lt;role&gt;actor&lt;/role&gt;&lt;/contributor&gt;&lt;/contributors&gt;
  &lt;/package&gt;
  </code></pre>
  
  <p>I have solved this issue when opening an xml file to work on using the below code:</p>
  
  <pre><code>from lxml import etree
  parser = etree.XMLParser(remove_blank_text=True) # makes pretty print work
  path3 = 'path_to_xml_file'
  open(path3)
  tree = etree.parse(path3, parser)
  root = tree.getroot()
  tree.write(xmlFileOut, pretty_print = True, xml_declaration = True, encoding = 'UTF-8')
  </code></pre>
  
  <p>This works, but how do I get it to work with a string xml?</p>