[DOMCore] error in setAttribute() spec?

DOM Core §5.7 defines the setAttribute() method with an algorithm that 
includes these final 2 steps:

>
> 4.    If the context object does not have an attribute whose local 
> name is qualifiedName, create an attribute, whose local name is 
> qualifiedName and value is value. Append this attribute to the context 
> object's attributes.
>
> 5.    Otherwise, set the value of the first attribute in the context 
> object's attributes whose qualified name is qualifiedName, to value. 

Note that step 4 compares the first method argument to attribute's local 
name, and step 5 compares the argument to the attribute's qualified 
name. I think (and I hope) that step 4 is incorrect and should compare 
against the qualified name like step 5 does.

As written, I think the spec calls for the following unexpected behavior:

// Create an element to test with
var e = document.createElement("div");
// Define an attribute qname foo:bar, local name bar
e.setAttributeNS("foo", "foo:bar", "1");
// Looks for attributes by qname, returns "1"
e.getAttribute("foo:bar")   // "1"
// Here's where it gets weird.  For this next line
// step 4 finds no attribute with localname "foo:bar"
// so it creates a new attribute with that as its local name.
// and as its qualified name.
e.setAttribute("foo:bar", "2");
// When we repeat the query we still get "1"
// because getAttribute find the first attribute with the
// specified qname.
e.getAttribute("foo:bar")  // "1"
// Now it gets weirder. We repeat the call to setAttribute()
// This time, the existance of the second attribute
// prevents the creation of a new one, but it is the first
// attribute that gets set:
e.setAttribute("foo:bar", "3");
// The first foo:bar changed, so this time we get "3"
e.getAttribute("foo:bar")  // "3"

That can't be right, can it?

     David

Received on Thursday, 25 August 2011 21:43:44 UTC