title: Adding <root> tag to XML doc with Python
body: <p>Attempting to add a root tag to the beginning and end of a 2mil line XML file so the file can be properly processed with my Python code. </p>
  
  <p>I tried using this code from a <a href="https://stackoverflow.com/questions/25714832/python-how-to-add-root-node-to-an-xml">previous post</a>, but I am getting an error "XMLSyntaxError: Extra content at the end of the document, line __, column 1"</p>
  
  <p>How do I solve this? Or is there a better way to add a root tag to the beginning and end of my large XML doc?</p>
  
  <pre><code>import lxml.etree as ET
  tree = ET.parse('test.xml')
  root = tree.getroot()
  newroot = ET.Element("root")
  newroot.insert(0, root)
  print(ET.tostring(newroot, pretty_print=True))
  </code></pre>
  
  <p><strong>My test XML</strong></p>
  
  <pre><code>&lt;pub&gt;
      &lt;ID&gt;75&lt;/ID&gt;
      &lt;title&gt;Use of Lexicon Density in Evaluating Word Recognizers&lt;/title&gt;
      &lt;year&gt;2000&lt;/year&gt;
      &lt;booktitle&gt;Multiple Classifier Systems&lt;/booktitle&gt;
      &lt;pages&gt;310-319&lt;/pages&gt;
      &lt;authors&gt;
          &lt;author&gt;Petr Slav&amp;iacute;k&lt;/author&gt;
          &lt;author&gt;Venu Govindaraju&lt;/author&gt;
      &lt;/authors&gt;
  &lt;/pub&gt;
  &lt;pub&gt;
      &lt;ID&gt;120&lt;/ID&gt;
      &lt;title&gt;Virtual endoscopy with force feedback - a new system for neurosurgical training&lt;/title&gt;
      &lt;year&gt;2003&lt;/year&gt;
      &lt;booktitle&gt;CARS&lt;/booktitle&gt;
      &lt;pages&gt;782-787&lt;/pages&gt;
      &lt;authors&gt;
          &lt;author&gt;Christos Trantakis&lt;/author&gt;
          &lt;author&gt;Friedrich Bootz&lt;/author&gt;
          &lt;author&gt;Gero Strau&amp;szlig;&lt;/author&gt;
          &lt;author&gt;Edgar Nowatius&lt;/author&gt;
          &lt;author&gt;Dirk Lindner&lt;/author&gt;
          &lt;author&gt;H&amp;uuml;seyin Kem&amp;acirc;l &amp;Ccedil;akmak&lt;/author&gt;
          &lt;author&gt;Heiko Maa&amp;szlig;&lt;/author&gt;
          &lt;author&gt;Uwe G. K&amp;uuml;hnapfel&lt;/author&gt;
          &lt;author&gt;J&amp;uuml;rgen Meixensberger&lt;/author&gt;
      &lt;/authors&gt;
  &lt;/pub&gt;
  </code></pre>