

def findall(root, xpath, attribute_name=None, attribute_value=None):
    'Find elements recursively from given root element based on\n    xpath and possibly given attribute\n\n    :param root: Element root element where to start search\n    :param xpath: xpath defintion, like {http://foo/bar/namespace}ElementName\n    :param attribute_name: name of possible attribute of given element\n    :param attribute_value: value of the attribute\n    :return: list of elements or None\n    '
    found_elements = []
    if (((2, 6) == sys.version_info[0:2]) and (which_etree() != 'lxml.etree')):
        elements = root.getiterator(xpath)
        if ((attribute_name is not None) and (attribute_value is not None)):
            for element in elements:
                if (element.attrib.get(attribute_name) == attribute_value):
                    found_elements.append(element)
        else:
            found_elements = elements
    else:
        if ((attribute_name is not None) and (attribute_value is not None)):
            xpath = ('%s[@%s="%s"]' % (xpath, attribute_name, attribute_value))
        found_elements = root.findall(('.//' + xpath))
    if (found_elements == []):
        found_elements = None
    return found_elements

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