def set_attr(obj, n, attr, val, default=None):
    """
    Set the specified attribute of an ElementTree ``Element`` object to the value from the
    specified target. 
    
    :param obj: An object which contains an ``ATTR_MAP`` property.
    :param n: An ElementTree ``Element`` object. 
    :param attr: The name of the attribute to set.
    :param val: The value of the attribute to set.
    :param default: The default value of ``val``. If ``val==default``, the attribute will not be set.
    
    """
    if default != None and val == default:
        return
    if obj.ATTR_MAP.has_key(attr):
        f = obj.ATTR_MAP[attr]
        s = f.to_str(val)
        if s != None:
            n.attrib[attr] = s
        return
    if val != None:
        s = str(val)
        n.attrib[attr] = s
