from lxml import etree, html
xml = """
    <tree id="A"><anotherelement/></tree>
    <tree id="B"><yetanotherelement/></tree>
"""
fragments = html.fragments_fromstring(xml)
root = etree.Element('root')
for f in fragments:
    root.append(f)
print(etree.tostring(root, pretty_print=True))
lxml Create XML fragment with no root element?