import xml.etree.ElementTree as ET xml_data = '<data><item name="apple" price="1.50"/><item name="banana" price="0.75"/></data>' root = ET.fromstring(xml_data) items = [{attr.tag: attr.attrib} for attr in root.findall('item')] print(f"Parsed XML Data: {items}")
Output:
Parsed XML Data: [{‘item’: {‘name’: ‘apple’, ‘price’: ‘1.50’}}, {‘item’: {‘name’: ‘banana’, ‘price’: ‘0.75’}}]