I am reading data from a python dictionary and trying to add more book elements in the below tree. Below is just an examplke, i need to copy an element with it's child(s) but replace the content, in this case i need to copy the book element but replace title and author.
<store>
<bookstore>
<book>
<title lang="en">IT book</title>
<author>Some IT Guy</author>
</book>
</bookstore>
</store>
I use this code:
root = et.parse('Template.xml').getroot()
bookstore = root.find('bookstore')
book = root.find('bookstore').find('book')
Then i run the loop through a dictionary and trying to add new book elements under the bookstore:
for bk in bks:
book.find('title').text = bk
bookstore.append(book)
The result is that book elements are added to the bookstore, however they all contain title from the last iteration of the loop. I know i am doing something wrong here, but i can't understand what. I tried:
book[0].append(book) and book[-1].append(book)
But it did not help.