def XMLTreeRecursion(node,handlers,res):
'''This is the dispatcher for a recursive walk through the XMLTree.
It is first called by "ProcessXMLTree" with the root of the tree as "tree"
and can in turn be called by handler routines to work on subtrees.'''
# node can be string node, a unicode node or a true node
if type(node) == types.StringType:
handlers.handleString(node,res) # default behaviour is a res.write
elif type(node) == types.UnicodeType:
handlers.handleString(node.encode('ISO-8859-1','replace'),res)
# note that we ignore encoding problems here!
# Now "node" must be a tuple:
elif node[0] == '<![CDATA[': # a CDATA section node
handlers.handleCDATA(node,res)
elif node[0] == '<!--': # a comment node
handlers.handleComment(node,res)
elif node[0] == '<?': # a processing instruction
handlers.handlePI(node,res)
elif hasattr(handlers,'handle_'+node[0]):
method = getattr(handlers,'handle_'+node[0])
method(node,res)
else:
handlers.handleDefault(node,res)
# For the processing of XML trees in memory we define a class:
评论列表
文章目录