XMLRewrite.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:OKUSON 作者: frankluebeck 项目源码 文件源码
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:
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号