Hi, David-

ddailey wrote (on 10/16/10 9:39 PM):
>
> I know that
>      R.setAttributeNS(null,"fill", "red")is the proper construction (for SVG
> but not HTML), rather than

Actually, that works with any XML language, XHTML included (provided it 
is real XHTML, and not served as text/html).


>      R.setAttribute("fill", "red")I also know that in every SVG viewer I have
> seen, the latter has equivalent behavior to the former (for SVG but not
> HTML), .

Both are fine for SVG; they are equivalent in this case.  The only place 
they are not equivalent is when the attribute is in a separate 
namespace, as with xlink:href; then, unfortunately, setAttributeNS is 
needed.  Another example of namespaced attributes is certain metadata 
attributes, or custom attributes; both Illustrator and Inkscape produce 
these, so it's good to have a grounding in them for advanced SVG stuff.

But in this case, the only thing to know there is that (for whatever 
reason) attributes are generally in the 'null' namespace (*not* in the 
SVG or HTML or whatever host-language namespace).  I recommend teaching 
setAttribute for normal attributes, and setAttributeNS only for xlink:href.


(Note that a younger me was rather outspoken about using setAttributeNS, 
as I thought it clarified the subtleties of namespaces through making 
them explicit.  I no longer feel that way, and think that people should 
do what is easiest; there is a little pain involved in learning 
namespaces, and as much as possible, we should remove that pain.  Bad 
Younger Me, no cookie.)


> I think I was told once that the SVG spec (or maybe it is the XML spec, or
> one or another DOM spec), for some mysterious reason, leaves room for some
> future browser manufacturer to make a browser in which the latter
> construction wouldn't work.

I don't believe any spec says so, but even if it does, that's not going 
to happen.  The current trend is for increased API simplicity, so newer 
specs and existing browsers will not go that way.  setAttribute is safe 
and future-proof.

Hope that helps-
-Doug


------------------------------------

-----
To unsubscribe send a message to: svg-developers-unsubscr...@yahoogroups.com
-or-
visit http://groups.yahoo.com/group/svg-developers and click "edit my 
membership"
----Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/svg-developers/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/svg-developers/join
    (Yahoo! ID required)

<*> To change settings via email:
    svg-developers-dig...@yahoogroups.com 
    svg-developers-fullfeatu...@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    svg-developers-unsubscr...@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

Reply via email to