Question: Create an xml file that contains the following xml code. Name the file books.xml , then answer the question below Giada De Laurentiis 2 0

Create an xml file that contains the following xml code. Name the file books.xml, then answer the question below
Giada De Laurentiis
2005
30.00
J K. Rowling
2005
29.99
James McGovern
Per Bothner
Kurt Cagle
James Linn
Vaidyanathan Nagarajan
2003
49.99
Erik T. Ray
2003
39.95
Fix the errors in the code below so that it reads the data from books.xml and finds all of the book data and prints the title for each book and then finds all the author names for each book and prints each author name.
import xml.etree.ElementTree as ET
fh = open("books.xml")
data = fh.read()
fh.close()
tree = ET.fromstring(data)
book_list = tree.find('book')
for book in book_list:
print(f'Book title: {book.find(title).text}')
author_list = book.find('author')
for author in author_list:
print(f"Author: {author}")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!