public void addAttribute(String key, Object value) {
        if (value == null) {
            return;
        }
        if (cachedTag == null) {
            throw new IllegalStateException("There is no open tag to add attributes to.");
        }
        if (!XML.isName(key)) {
            throw new IllegalArgumentException("The name '" + key
                    + "' cannot be used as an XML attribute name. Legal names must adhere to"
                    + " http://www.w3.org/TR/2006/REC-xml11-20060816/#sec-common-syn");
        }
        cachedAttribute.add(new Attribute(key, value));
    }
Add a new XML attribute to the last tag started.
The tag cannot already have had content added to it, or been ended.
If a null value is added, the attribute will be skipped.

@param key   the attribute name
@param value the attribute value
document/src/main/java/com/yahoo/document/serialization/XmlStream.java