d3m
d3m

Reputation: 475

XML parsing with ElementTree produces wrong output

I want to parse an XML file with ElementTree but at a certain tag the output is wrong

<descriptions>
<description descriptionType="Abstract">Some Abstract Text
</description>
</descriptions>

So I parse it with the XML function

import xml.etree.ElementTree as ElementTree
root = ElementTree.XML(my_xml)
root.getchildren()[0].items()

and the outcome is:

Out: [('descriptionType', 'Abstract')]

Is there any problem with the XML, I use ElementTree in a wrong way or it's a bug?

Upvotes: 0

Views: 114

Answers (2)

wrgrs
wrgrs

Reputation: 2569

I guess you want to get the text. So:

root.getchildren()[0].text

not

root.getchildren()[0].items()

Upvotes: 1

d3m
d3m

Reputation: 475

It was just that if there are no tags its stored in the text attribute..

Upvotes: 0

Related Questions