Locally Forced Generation

A token can be forced to generate its following token, which in the case of a markupTokenStartElement is its first child:

for token in parser ():
   if token.isStartElement ("chapter"):
      chapCount += 1
      secCount = 0
      if token.next.isStartElement ("title"):
         out.write ("<H2>" + str (chapCount) + ". ")
         processParaContent (parser, out)
         out.write ("</H2>")
      processSectionContent (parser, out)
New Models for Processing Text and XML with Python Sam Wilmott
Slide 37 of 51        www.wilmott.ca