Sequential Processing With Context

A nested generator generates only the content of the currently open element:

for token in parser ():
   if token.isStartElement ("randlist"):
      out.write ("<UL>\n")
      for token in parser ():
         if token.isStartElement ("li"):
            out.write ("<LI>")
            processSectionContent (parser, out)
            out.write ("</LI>\n")
      out.write ("</UL>\n")
New Models for Processing Text and XML with Python Sam Wilmott
Slide 36 of 51        www.wilmott.ca