title: lxml not adding newlines when inserting a new element into existing xml
body: <p>I have a large set of existing xml files, and I am trying to add one element to all of them (they are pom.xml for a number of maven projects, and I am trying to add a parent element to all of them). The following is my exact code.</p>
  
  <p>The problem is that the final xml output in pom2.xml has the complete <code>parent</code> element in a single line. Though, when I print the element by itself, it writes it out in 4 lines as usual. How do I print out the complete xml with proper formatting for the <code>parent</code> element?</p>
  
  <pre><code>from lxml import etree
  
  parentPom = etree.Element('parent')
  groupId = etree.Element('groupId')
  groupId.text = 'org.myorg'
  parentPom.append(groupId)
  
  artifactId = etree.Element('artifactId')
  artifactId.text = 'myorg-master-pom'
  parentPom.append(artifactId)
  
  version = etree.Element('version')
  version.text = '1.0.0'
  parentPom.append(version)
  
  print etree.tostring(parentPom, pretty_print=True)
  
  pom = etree.parse("pom.xml")
  projectElement = pom.getroot()
  projectElement.insert(0, parentPom)
  
  file = open("pom2.xml", 'wb')
  file.write(etree.tostring(projectElement, pretty_print=True))
  file.close()
  </code></pre>
  
  <p>Output of print:</p>
  
  <pre><code>&lt;parent&gt;
    &lt;groupId&gt;org.myorg&lt;/groupId&gt;
    &lt;artifactId&gt;myorg-master-pom&lt;/artifactId&gt;
    &lt;version&gt;1.0.0&lt;/version&gt;
  &lt;/parent&gt;
  </code></pre>
  
  <p>Output of same element in pom2.xml:</p>
  
  <pre><code>&lt;parent&gt;&lt;groupId&gt;com.inmobi&lt;/groupId&gt;&lt;artifactId&gt;inmobi-master-pom&lt;/artifactId&gt;&lt;version&gt;1.0.1&lt;/version&gt;&lt;/parent&gt;&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  </code></pre>