[Tutor] Parsing an XML document using ElementTree

Alan Gauld alan.gauld at btinternet.com
Tue May 24 12:20:32 CEST 2011


"Sithembewena Lloyd Dube" <zebra05 at gmail.com> wrote


> And now, to iterate through its child nodes and print out the text 
> of each
> node:
>
>>>>for node in xml_content.getiterator('contest'):
> ...        name = node.attrib.get('text')
> ...        print name
> ...
>>>>
>
> Nothing is printed,
>
>>>> i = 0
>>>> for node in xml_content.getiterator('contest'):
> ...     i += 1
> ...
>>>> i
> 0
>
> What am I getting wrong? Any hints would be appreciated.

Looks like you are getting an empty list back.
Try printing list(xml_content.getiterator('contest'))

And if thats empty try checking the case of your tag?
I'm pretty sure it will be case sensitive?

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list