A Simple Generator
Nested elements can be processed in place, or content processing can be packaged in functions:
for token in parser (): if token.isCharacters (): out.write (escapeText (token.characters)) elif token.isStartElement ("verbatim"): out.write ("<TT>") processParaContent (parser, out) out.write ("</TT>") elif token.isStartElement ("graphic"): out.write ("<IMG SRC=\"" + unparsedEntity \ [token.attribute ["figname"]].systemId + \ "\">")