tree = etree.parse('books.xml')
new_entry = etree.fromstring(
    """<book category="web" cover="paperback">
<title lang="en">Learning XML 2</title>
<author>Erik Ray</author>
<year>2006</year>
<price>49.95</price>
</book>"""
    )
root = tree.getroot()
root.append(new_entry)
f = open('books-mod.xml', 'w')
f.write(etree.tostring(root, pretty_print=True))
Как обновить файл XML с помощью lxml