

def etree_to_dict(etree, namespace=None, tag_list=True, convert_camelcase=False):
    '\n    Convert an etree to a dict.\n   \n    **Keyword arguments:**\n     * *namespace* -- XML Namespace to be removed from tag names (Default None)\n    '
    children = etree.getchildren()
    if (len(children) == 0):
        return etree.text
    children_dict = {
        
    }
    for element in children:
        tag = element.tag
        if (namespace is not None):
            tag = tag.replace(namespace, '')
        if convert_camelcase:
            tag = camelcase_to_underscore(tag)
        element_dict = etree_to_dict(element, namespace=namespace, tag_list=tag_list, convert_camelcase=convert_camelcase)
        if (tag in children_dict):
            if (not isinstance(children_dict[tag], list)):
                children_dict[tag] = [children_dict[tag]]
            children_dict[tag].append(element_dict)
        elif tag_list:
            children_dict[tag] = [element_dict]
        else:
            children_dict[tag] = element_dict
    return children_dict

dataset/ETHPy150Open wehriam/awspider/awspider/aws/lib.py etree_to_dict/original