Subj : Re: E4X: should xmlObject.attributes() return all attributes or only To : netscape.public.mozilla.jseng From : Brendan Eich Date : Fri Apr 08 2005 04:21 pm Martin Honnen wrote: > > Test case: > > var p =
Kibology for all.
; > 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 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 .