def get_xml_attrib(xml_tree,tag,attrib,repeated=False):
    """ 
    Extract xml attribute
    
    If repeated = True, first occurrence of attribute is stored.
    Else, its last occurrence is stored.
    """
    attribute =  None
    for element in xml_tree.iter(tag=tag):
        attribute = element.attrib[attrib]
        if repeated: break

    if attribute is None: raise ValueError('xml attribute %s not found'%attrib)
    else: return attribute