var p = <p id="p1" class="style1" xml:lang="en">Kibology for all.</p>;
print("attributes().length(): " + p.attributes().length());
yields 2 with Spidermonkey and 3 with Rhino.
The specs says "The attributes method returns an XMLList containing the
XML attributes of this object." which lets me expect I get all
attributes. However the formal definition then says
Return the result of calling the [[Get]] method of x with argument
ToAttributeName("*")
and trying to read through the specification to understand what that
should return it appears that only the attributes in no namespace are to
be returned.
Is that a bug in the spec? If there is a method called attributes why
does it not return all attributes regardless of whether they are in a
namespace or not?
The only way to consistently get all attributes with Rhino and
Spidermonkey is
print("p.@*::*.length(): " + p.@*::*.length());
but it seems odd that the method attributes does not yield all
attributes. If that is intended then the spec should maybe be fixed to
specificially state that the method attributes only returns attributes
in no namespace.
--
Martin Honnen
http://JavaScript.FAQTs.com/
Here is where the nice prose with examples added to aid understanding in
ECMA-357, missing from ECMA-262, can be a hazard. This is not a
rigorous definition, and in fact it's either misleading, or the
algorithm in the spec is buggy.
> Return the result of calling the [[Get]] method of x with argument
> ToAttributeName("*")
> and trying to read through the specification to understand what that
> should return it appears that only the attributes in no namespace are to
> be returned.
That's correct. From 13.4.4.5, see 10.5, then see 10.5.1, then see
13.2.2 2(b) in particular. The resulting AttributeName used to match
attributes has a [[Name]] internal property that's a QName with uri ===
"" and localName === "*".
That will not match all attributes. It will match only attributes in
the null namespace (or in no namespace, another way of saying the same
thing), which unprefixed attributes go in by default (even if there's a
default namespace declared for the containing tag).
> Is that a bug in the spec? If there is a method called attributes why
> does it not return all attributes regardless of whether they are in a
> namespace or not?
It may be a bug in the spec, because ToAttributeName("*") does something
different from new QName("*"). The latter results in a name whose uri
=== null, which would match any attribute, no matter what namespace it
is in.
> The only way to consistently get all attributes with Rhino and
> Spidermonkey is
> print("p.@*::*.length(): " + p.@*::*.length());
> but it seems odd that the method attributes does not yield all
> attributes. If that is intended then the spec should maybe be fixed to
> specificially state that the method attributes only returns attributes
> in no namespace.
Bcc'ing once again some folks who might be able to do something about
the spec.
/be
> That will not match all attributes. It will match only attributes in
> the null namespace (or in no namespace, another way of saying the same
> thing), which unprefixed attributes go in by default (even if there's a
> default namespace declared for the containing tag).
Strike the "by default" -- unprefixed attributes are in the null
namespace, period -- whether there is a declared default xmlns= or not.
/be