base.py 文件源码

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

项目:antares 作者: CONABIO 项目源码 文件源码
def _xml_to_json(element, stack, dictionary):
    '''
    This method creates a json representation of the given xml structure. It
    traverses the dom tree and adds elements to the dictionary as it goes.
    '''
    stack.append(element.nodeName)
    LOGGER.debug('Processing %s element.', element.nodeName)
    if (
        element.firstChild and
        element.firstChild.nodeValue and
        len(element.firstChild.nodeValue.strip())
        ):
        put_in_dictionary(dictionary, stack, parse_value(element.firstChild.nodeValue.strip()))
    else:
        # This line might be removed.
        put_in_dictionary(dictionary, stack, {})
    for child in element.childNodes:
        if child.nodeType == dom.Node.ELEMENT_NODE:
            _xml_to_json(child, stack, dictionary)
            stack.pop()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号