def _find_namespaces_from_child(parent, child, namespaces):
    """Recursively searches from the parent to the child,
    gathering all the applicable namespaces along the way"""
    for cur_child in parent.childNodes:
        if cur_child is child:
            return True
        if _find_namespaces_from_child(cur_child, child, namespaces):
            # we are the parent node
            for key in cur_child.attributes.keys():
                if key.startswith('xmlns:') or key == 'xmlns': 
                    namespaces[key] = cur_child.attributes[key]
            break
    return False