}
else {
prefix = qualifiedName.substring(0, index);
localName = qualifiedName.substring(index + 1);
}
Attr newAttr = getAttributeNodeNS(namespaceURI, localName);
if (newAttr == null) {
// REVISIT: this is not efficient, we are creating twice the same
// strings for prefix and localName.
newAttr = getOwnerDocument().createAttributeNS(
namespaceURI,
qualifiedName);
if (attributes == null) {
attributes = new AttributeMap(this, null);
}
newAttr.setNodeValue(value);
attributes.setNamedItemNS(newAttr);
}
else {
if (newAttr instanceof AttrNSImpl){
// change prefix and value
((AttrNSImpl)newAttr).name= (prefix!=null)?(prefix+":"+localName):localName;
}
else {
// This case may happen if user calls:
// elem.setAttribute("name", "value");
// elem.setAttributeNS(null, "name", "value");
// This case is not defined by the DOM spec, we choose
// to create a new attribute in this case and remove an old one from the tree
// note this might cause events to be propagated or user data to be lost
newAttr = ((CoreDocumentImpl)getOwnerDocument()).createAttributeNS(namespaceURI, qualifiedName, localName);
attributes.setNamedItemNS(newAttr);
}
newAttr.setNodeValue(value);
}
} // setAttributeNS(String,String,String)