'Collect errors from an error tree
@param job: the import job, resource or error tree as Element'

@staticmethod
def collect_errors(job):

    errors = []
    try:
        if isinstance(job, etree._Element):
            error_tree = job
        else:
            error_tree = job.error_tree
    except AttributeError:
        return errors
    if (error_tree is None):
        return errors
    elements = error_tree.xpath('.//*[@error]')
    for element in elements:
        get = element.get
        if (element.tag == 'data'):
            resource = element.getparent()
            value = get('value')
            if (not value):
                value = element.text
            error = ("%s,    %s:    '%s'    (value='%s')" % (resource.get('name', None), get('field', None), get('error', None), value))
        if (element.tag == 'reference'):
            resource = element.getparent()
            error = ("%s,    %s:    '%s'" % (resource.get('name', None), get('field', None), get('error', None)))
        elif (element.tag == 'resource'):
            error = ('%s:    %s' % (get('name', None), get('error', None)))
        else:
            error = ('%s' % get('error', None))
        errors.append(error)
    return errors
