[Solved] how to create a list of elements from an XML file in python


1) Try this:

import xml.etree.ElementTree as ET
    Books = ET.parse('4.xml') #parse the xml file into an elementtre
    root = Books.getroot()
    for child in root:
        BookInfo = [
        child.find('title').text,
        child.find('author').text,
        child.find('year').text,
        child.find('price').text
        ]
        print (BookInfo)

2)if you can receive the specific element from the list use BookInfo[0] – this is title, BookInfo[1] – author…

solved how to create a list of elements from an XML file in python