utils.py 文件源码

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

项目:pywxclient 作者: justdoit0823 项目源码 文件源码
def dict2xml(data):
    """Convert dict to xml document."""
    document = Document()

    def create_node(root, node_data):

        for key, val in node_data.items():
            node = document.createElement(key)
            if isinstance(val, dict):
                attrs = val.pop('__attrs__', {})
                for attr, attr_val in attrs.items():
                    node.setAttribute(attr, attr_val)

                create_node(node, val)
            elif isinstance(val, (tuple, list)):
                for sub_data in val:
                    create_node(node, sub_data)
            else:
                node.appendChild(document.createTextNode(str(val)))

            root.appendChild(node)

    create_node(document, data)

    return document.childNodes[0].toxml()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号