python
import xmltodict
xml_data = """
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J.K. Rowling</author>
<year>2003</year>
<price>29.99</price>
</book>
</bookstore>
"""
data_dict = xmltodict.parse(xml_data)
print(data_dict)
{
'bookstore': {
'book': [
{
'@category': 'cooking',
'title': {
'@lang': 'en',
'#text': 'Everyday Italian'
},
'author': 'Giada De Laurentiis',
'year': '2005',
'price': '30.00'
},
{
'@category': 'children',
'title': {
'@lang': 'en',
'#text': 'Harry Potter'
},
'author': 'J.K. Rowling',
'year': '2003',
'price': '29.99'
}
]
}
}