iterate over a series of nodes in an XML file

rajarshi.guha at gmail.com rajarshi.guha at gmail.com
Wed Jul 5 13:46:55 EDT 2006


Hi, I have an XML file which contains entries of the form:

<idlist>
 <myID>1</myID>
 <myID>2</myID>
....
 <myID>10000</myID>
</idlist>

Currently, I have written a SAX based handler that will read in all the
<myID></myID> entries and return a list of the contents of these
entries. However this is not scalable and for my purposes it would be
better if I could iterate over the list of <myID> nodes. Some thing
like:

for myid in getMyIDList(document):
   print myid

I realize that I can do this with generators, but I can't see how I can
incorporate generators into my handler class (which is a subclass of
xml.sax.ContentHandler).

Any pointers would be appreciated

Thanks,
Rajarshi




More information about the Python-list mailing list