

def xml_to_dict(root, prefix=None, depth=1, diction=None):
    '\n        Recursively iterates through an xml element to convert each element in the tree to a (key,val). Where key is the element\n        tag and val is the inner-text of the element. Note that this recursively go through the tree until the depth specified.\n\n        Parameters\n        ===========\n        :root - root xml element, starting point of iteration\n        :prefix - a string to prepend to the resulting key (optional)\n        :depth - the number of depths to process in the tree (optional)\n        :diction - the dictionary to insert the (tag,text) pairs into (optional)\n\n        Return\n        =======\n        Dictionary of (key,value); where key is the element tag stripped of namespace and cleaned up to be pep8 and\n        value is the inner-text of the element. Note that duplicate elements will be replaced by the last element of the \n        same tag in the tree.\n    '
    ret = (diction if (diction is not None) else dict())
    for child in root:
        val = testXMLValue(child)
        if ((val is None) or (val == '')):
            if (depth > 1):
                ret = xml_to_dict(child, prefix=prefix, depth=(depth - 1), diction=ret)
            continue
        key = format_string(child.tag.split('}')[(- 1)])
        if (prefix is not None):
            key = (prefix + key)
        ret[key] = val
        if (depth > 1):
            ret = xml_to_dict(child, prefix=prefix, depth=(depth - 1), diction=ret)
    return ret

dataset/ETHPy150Open geopython/OWSLib/owslib/util.py xml_to_dict/original