xmlutils.py 文件源码

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

项目:respeaker_virtualenv 作者: respeaker 项目源码 文件源码
def annotate_with_XMLNS(tree, prefix, URI):
    """
    Annotates the provided DOM tree with XMLNS attributes and adds XMLNS
    prefixes to the tags of the tree nodes.

    :param tree: the input DOM tree
    :type tree: an ``xml.etree.ElementTree.ElementTree`` or
        ``xml.etree.ElementTree.Element`` object
    :param prefix: XMLNS prefix for tree nodes' tags
    :type prefix: str
    :param URI: the URI for the XMLNS definition file
    :type URI: str

    """
    if not ET.iselement(tree):
        tree = tree.getroot()
    tree.attrib['xmlns:' + prefix] = URI
    iterator = tree.iter()
    next(iterator)  # Don't add XMLNS prefix to the root node
    for e in iterator:
        e.tag = prefix + ":" + e.tag
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号