'Add an attribute to the element
This is sort of a convenience method. All attributes in ODF have
namespaces. The library knows what attributes are legal and then allows
the user to provide the attribute as a keyword argument and the
library will add the correct namespace.
Must overwrite, If attribute already exists.'

def setAttribute(self, attr, value, check_grammar=True):

    allowed_attrs = self.allowed_attributes()
    if (allowed_attrs is None):
        if (type(attr) == type(())):
            (prefix, localname) = attr
            self.setAttrNS(prefix, localname, value)
        else:
            raise AttributeError, 'Unable    to    add    simple    attribute    -    use    (namespace,    localpart)'
    else:
        allowed_args = [a[1].lower().replace('-', '') for a in allowed_attrs]
        if (check_grammar and (attr not in allowed_args)):
            raise AttributeError, ('Attribute    %s    is    not    allowed    in    <%s>' % (attr, self.tagName))
        i = allowed_args.index(attr)
        self.setAttrNS(allowed_attrs[i][0], allowed_attrs[i][1], value)
