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")