I want to update xml file with new information by using lxml library. For example, I have this code:
>>> from lxml import etree
>>>
>>> tree = etree.parse('books.xml')
where 'books.xml' file, has this content: http://www.w3schools.com/dom/books.xml
I want to update this file with new book:
>>> 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>''')
My question is, how can I update tree
element tree with new_entry
tree and save the file.