xmlstorage.py 文件源码

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

项目:log-with-git 作者: iesugrace 项目源码 文件源码
def recordToSource(recordData):
        """ Compose Xml source code from a
        record's data which is a dict object.
        """
        from xml.dom.minidom import Document, Text
        import re
        doc  = Document()
        root = doc.createElement("log")
        doc.appendChild(root)
        items  = dict(recordData).items()
        fields = Record.convertFields(items, False)

        # sort the fields data according to the definition order
        orders = {k: v['order'] for k, v in Record.fields.items()}
        sortKey = lambda x: orders[x[0]]
        fields = sorted(fields.items(), key=sortKey)

        for name, value in fields:
            XmlStorage.createNode(root, name, value)
        xmlCode = doc.toprettyxml()
        xmlCode = re.sub('\t', ' ' * 4, xmlCode)    # replace tabs with spaces
        return xmlCode
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号