XML

  • elements
<root>
<docs>
<doc id="1"> # id is attribute of doc
<text> blahblah </text> # text is element of doc
<doc id="3">
<text> blahblah2 </text>
</docs>
</root>
docs = root.findall('./docs/doc')
row = []
for doc in docs: # retrieve attrib of doc
id = doc.attrib['id']
#retrieve element text from doc && record contents using .text
txt = doc.find('./text').text
row.append({'id': id, 'text': txt})

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store