[XML-SIG] Learning to use elementtree
Stefan Behnel
stefan_ml at behnel.de
Tue Apr 8 16:14:17 CEST 2008
Doran, Harold wrote:
> for statentityref in statentityref.findall('statentityref'):
In this line, you assign new values to the name "statentityref" in each
iteration of the loop.
> for statval in statentityref.findall('statval'):
> print >> f, statentityref.attrib['id'], '\t',
Here, you access the attribute "id" of the element you referenced by that
name, which is different in each iteration. But only the first element
seems to have a meaningful value for this attribute.
You should
a) read the Python tutorial, especially the chapter on loops, and
b) assign the value of the "id" attribute to a variable outside the loop
and print it inside the loop
Stefan
More information about the XML-SIG
mailing list