So either the document or the implementation needs to be change. Is
hasAttribute("attr") alot faster than getAttribute("attr") == "true" ?
Is if(val)setAttribute("attr","true");else removeAttribute("attr"); faster than
setAttribute("attr", val ? "true" : "false" ); ?
basic
This was changed not long ago after nsIContent::HasAttr() was
implemented by hewitt. Blake and/or bz changed XUL to use
removeAttribute in conjunction with hasAttribute. In my opinion the XUL
spec should be changed.
-Fabian.
> basic
>
XML schemas have a notion of an attribute being a boolean type. Being a
boolean type means having two possible values, true and false. If we do
not adhere to this specification, then we end up with our own fruity
definition of a pseudo-boolean that wouldn't mesh with the xsd:boolean type.
Dave
(hy...@netscape.com)
Fabian Guisset wrote:
>
> ------------------------------------------------------------------------
>
> Subject:
>
> Re: xul boolean attributes
> From:
>
> Fabian Guisset <fgui...@softhome.net>
> Date:
>
> Mon, 07 Jan 2002 18:24:44 +0100
>
> Newsgroups:
>
> netscape.public.mozilla.xpfe
I'll start writing patches for bug 118683
<http://bugzilla.mozilla.org/show_bug.cgi?id=118683> to change hasAttribute to
getAttribute. since an empty attribute also works with getAttribute and
removeAttribute is faster than setAttribute, I'll leave removeAttribute alone.
basic
<quote>
http://www.w3.org/TR/xmlschema-2/#boolean
3.2.2.1 Lexical representation
An instance of a datatype that is defined as ·boolean· can have the following
legal literals {true, false, 1, 0}.
3.2.2.2 Canonical representation
The canonical representation for boolean is the set of literals {true, false}.
</quote>
basic
The basic rules to follow are these:
(1) When writing code that wants to change the value of an attribute to
false, use removeAttribute (since it preserves space and also means
"false" for all XUL boolean attributes).
(2) Code that wishes to check a boolean attribute's value should always
operate under the following assumptions:
(a) If the attribute is present, set to "true", then the value is true
(b) If the attribute is present, set to "false", then the value is false
(c) If the attribute is present and set to anything else, the behavior
is undefined (for consistency you could just assume "false" here)
(d) If the attribute is absent, then the default value as specified by
the schema would be assumed (this is almost always "false" for XUL
boolean attributes, which is why removeAttribute is encouraged over
setattribute to "false").
basic wrote:
>
> ------------------------------------------------------------------------
>
> Subject:
>
> Re: xul boolean attributes
> From:
>
> basic <_ba...@yahoo.com>
> Date:
>
> Wed, 09 Jan 2002 01:48:18 +0800
>
> Newsgroups:
>
> netscape.public.mozilla.xpfe
basic
dave
basic
dave
basic wrote:
>
> ------------------------------------------------------------------------
>
> Subject:
>
> Re: xul boolean attributes
> From:
>
> basic <_ba...@yahoo.com>
> Date:
>
> Wed, 09 Jan 2002 07:58:32 +0800
>
> Newsgroups:
>
> netscape.public.mozilla.xpfe
Blake