0

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?

2 Answers 2

1

I guess you want to get the text. So:

root.getchildren()[0].text

not

root.getchildren()[0].items()
Sign up to request clarification or add additional context in comments.

3 Comments

yeah I realised that afterwards. thanx!
I answered the same thing before you :-/
Ha. My answer's better! But seriously, this isn't just for you, it's for other people reading the question later as well. So you could mark yours as correct if you like. Then everyone knows what the answer is. p.s. But you're right, I wanted the points. That's gamification: codinghorror.com/blog/2011/10/the-gamification.html
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.