My sample xml is
<RecordContainer RecordNumber = "1">
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
</catalog>
</RecordContainer>
<RecordContainer RecordNumber = "2">
<catalog>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
</catalog>
</RecordContainer>
My code to parse the above
import xml.etree.ElementTree as ET
tree = ET.fromstring("<root>"+ sample_data + "</root>")
Now after parsing I want to covert it to pandas dataframe or a csv file. To convert to pandas dataframe following is my code
def f(elem, result):
result[elem.tag] = elem.text
cs = elem.getchildren()
for c in cs:
result = f(c, result)
return result
d = f(tree, {})
df = pd.DataFrame(d, index=['values'])
But the above code is returning me empty value in df.
How do I convert above parsed xml to pandas df or csv file?