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.
I tried using this code from a previous post, but I am getting an error "XMLSyntaxError: Extra content at the end of the document, line __, column 1"
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?
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))
My test XML
<pub>
<ID>75</ID>
<title>Use of Lexicon Density in Evaluating Word Recognizers</title>
<year>2000</year>
<booktitle>Multiple Classifier Systems</booktitle>
<pages>310-319</pages>
<authors>
<author>Petr Slavík</author>
<author>Venu Govindaraju</author>
</authors>
</pub>
<pub>
<ID>120</ID>
<title>Virtual endoscopy with force feedback - a new system for neurosurgical training</title>
<year>2003</year>
<booktitle>CARS</booktitle>
<pages>782-787</pages>
<authors>
<author>Christos Trantakis</author>
<author>Friedrich Bootz</author>
<author>Gero Strauß</author>
<author>Edgar Nowatius</author>
<author>Dirk Lindner</author>
<author>Hüseyin Kemâl Çakmak</author>
<author>Heiko Maaß</author>
<author>Uwe G. Kühnapfel</author>
<author>Jürgen Meixensberger</author>
</authors>
</pub>