Question: Reading and Parsing XML files I know you do not have the file I just need the code...thank you! Use ElementTree() to read and parse

Reading and Parsing XML files

I know you do not have the file I just need the code...thank you!

Use ElementTree() to read and parse file best_selling_books.xml 1. Use ET.parse('best_selling_books.xml') to read and part the XML file into mytree 2. Use mytree.getroot() to get the root of the tree in myroot

3. Use a for loop to findall('BOOK') elements, then ... 4. Use .find('TITLE').text to get the TITLE text from each book element 5. Use .find('AUTHOR').text to get the AUTHOR text from each book element 6. Use .find('PUBLISHED').text to get the PUBLISHED year from each book element 7. Use .find('SALES').text to get the SALES text from each book element 8. Use .find('GENRE').text to get the GENRE text from each book element 9. Create a STRING variable named book_info by concatenating the 5 fields: TITLE, AUTHOR, PUBLISHED, SALES, GENRE. -- Separate each field with a SPACE COLON SPACE (' : ') to make the output easier to read! -- EXAMPLE: The Hobbit : J. R. R. Tolkien : 1937 : 100 million : Fantasy 10. Print the book_info

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 Databases Questions!