Re: [svg-developers] explaining setAttribute, setAttributeNS and carburetors

2010-10-17 Thread ddailey
Jacob, Doug and Wade,

Thanks for your assistance here. It definitely helps!

regards
David
  - Original Message - 
  From: Jacob Beard 
  To: svg-developers 
  Sent: Sunday, October 17, 2010 3:59 AM
  Subject: Re: [svg-developers] explaining setAttribute, setAttributeNS and 
carburetors



  On Sun, Oct 17, 2010 at 6:48 AM, Doug Schepers d...@schepers.cc wrote:

   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.

  The DOM Level 2 Core spec has something to say about mixing
  namespace-aware DOM methods with non-namespace-aware DOM methods:

  Note: DOM Level 1 methods are namespace ignorant. Therefore, while it
  is safe to use these methods when not dealing with namespaces, using
  them and the new ones at the same time should be avoided. DOM Level 1
  methods solely identify attribute nodes by their nodeName. On the
  contrary, the DOM Level 2 methods related to namespaces, identify
  attribute nodes by their namespaceURI and localName. Because of this
  fundamental difference, mixing both sets of methods can lead to
  unpredictable results. In particular, using setAttributeNS, an element
  may have two attributes (or more) that have the same nodeName, but
  different namespaceURIs. Calling getAttribute with that nodeName could
  then return any of those attributes. The result depends on the
  implementation. Similarly, using setAttributeNode, one can set two
  attributes (or more) that have different nodeNames but the same prefix
  and namespaceURI. In this case getAttributeNodeNS will return either
  attribute, in an implementation dependent manner. The only guarantee
  in such cases is that all methods that access a named item by its
  nodeName will access the same item, and all methods which access a
  node by its URI and local name will access the same node. For
  instance, setAttribute and setAttributeNS affect the node that
  getAttribute and getAttributeNS, respectively, return.
  http://www.w3.org/TR/DOM-Level-2-Core/core.html

  So, it seems like if you're strictly following the spec, mixing
  setAttribute and setAttributeNS might not be the best idea, as it may
  lead to inconsistent results across implementations. In practice, I
  very rarely use the non-namespaced versions (only when I need to do a
  bit of HTML DOM scripting in IE), so this may work just fine.

  Best,

  Jake


  

[Non-text portions of this message have been removed]





-
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/



Re: [svg-developers] explaining setAttribute, setAttributeNS and carburetors

2010-10-17 Thread Doug Schepers
Hi, Jacob-

Jacob Beard wrote (on 10/17/10 3:59 AM):
 Note: DOM Level 1 methods are namespace ignorant. Therefore, while it
 is safe to use these methods when not dealing with namespaces, using
 them and the new ones at the same time should be avoided.

Thanks for digging that up.  I think the author of that may actually 
have been a bit confused... or at least, they didn't state the facts 
clearly.  (There may have been a bit of propagandizing there, as well, 
to get people to use XML namespaces more, perhaps.)

Indeed, if you try to set a namespaced attribute with setAttribute(), it 
won't work correctly... the attribute will be placed in the null 
namespace.  So, when you use

  el.setAttribute( xlink:href, #foo );

it's the equivalent of using

  el.setAttributeNS( null, xlink:href, #foo );

where the local node-name (unintuitively) is 'xlink:href', not 'href' in 
the XLink namespace.

But that's only when you're dealing with namespaces.  Since most 
attributes are in the null namespace, and setAttribute() places 
everything in the null namespace, then these are equivalent and 
perfectly safe:

  el.setAttribute( fill, #f00 );
  el.setAttributeNS( null, fill, #f00 );


As an aside, this is actually a rather poor design, which could have 
been made better if they had simply accounted for hardcoded prefixed to 
be bound to specific namespaces, rather than introducing the arbitrary 
level of abstraction where any namespace could have any prefix string; 
this is made a bit simpler in HTML5, which does define a few hardcoded 
prefixes for namespaces.  Maybe in some future version of XML, XML 
Namespaces, or the like, this can be be expanded beyond HTML.

Regards-
-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/



[svg-developers] explaining setAttribute, setAttributeNS and carburetors

2010-10-16 Thread ddailey
I don't really understand carburetors, but I have a vague idea that they 
control the richness of the fuel mixture so as to calibrate the rate of 
combustion in the engine -- for me, the following issue is similar.

Perhaps you can help. I'm trying to explain how to do a wee bit of DOM 
scripting to those who don't necessarily have any programming background, 
let alone DOM scripting in SVG. I generally get around the topic on my own, 
okay, without really understanding some of the more esoteric subjects like 
DOCTYPE and namespaces and so forth -- I just do what people tell me to and 
it usually works. In truth, I consider all such things to be incantations 
required for me to pay homage to the systems gurus who have figured out how 
to glue all the pieces together. They are like taxes, and it is generally 
not crucial that I understand them so long as I do what is required.

On the other hand, once every so often I find myself having to explain 
things to others. And it is at these times that I find myself thinking that 
perhaps I should understand such myseries (did I forget a t in the last 
word? oops) a bit deeper than I do. Hence the following question:

I know that
R.setAttributeNS(null,fill, red)is the proper construction (for SVG 
but not HTML), rather than
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), .

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.  So, as per my oversimplified understanding, we 
use the more arcane construction (and its extra seven keystrokes and the 
extra 80,000 neural synapses) in anticipation of such a possible future. I 
truly don't rue the seven keystrokes, as much as all the norepinephrine, 
seratonin and the like.

So as I say, it is not important that I understand it. There may be, 
already, a shortage of norepinephrine which would preclude me from ever 
understanding it. But what words might I use to explain this oddity to 
others? If I happen to understand your explanation that will be a 
serendipitous but unexpected side-effect!

cheers
David






-
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/



Re: [svg-developers] explaining setAttribute, setAttributeNS and carburetors

2010-10-16 Thread G. Wade Johnson
Hi David,

Let me start by saying that I don't have a definitive answer on this,
but I do have some vague recollections that might help.

On Sat, 16 Oct 2010 21:39:39 -0400
ddailey ddai...@zoominternet.net wrote:

 I don't really understand carburetors, but I have a vague idea that
 they control the richness of the fuel mixture so as to calibrate the
 rate of combustion in the engine -- for me, the following issue is
 similar.
 
 Perhaps you can help. I'm trying to explain how to do a wee bit of
 DOM scripting to those who don't necessarily have any programming
 background, let alone DOM scripting in SVG. I generally get around
 the topic on my own, okay, without really understanding some of the
 more esoteric subjects like DOCTYPE and namespaces and so forth -- I
 just do what people tell me to and it usually works. In truth, I
 consider all such things to be incantations required for me to pay
 homage to the systems gurus who have figured out how to glue all the
 pieces together. They are like taxes, and it is generally not crucial
 that I understand them so long as I do what is required.
 
 On the other hand, once every so often I find myself having to
 explain things to others. And it is at these times that I find myself
 thinking that perhaps I should understand such myseries (did I forget
 a t in the last word? oops) a bit deeper than I do. Hence the
 following question:
 
 I know that
 R.setAttributeNS(null,fill, red)is the proper construction
 (for SVG but not HTML), rather than
 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), .

I remember in the early days of XML, namespaces did not exist and any
tools/languages that did the DOM-thing were built around the second
model. Later, namespaces were added and as the tools/languages began
sprouting the first form.

During that time, I remember many people running across and reporting
problems with the setAttributeNS() methods not working consistently
among tools when working with XML having namespaces. After lots of
discussion and consternation, it seems the consensus was that
setAttribute( ... ) was not safe to use when any namespaces were present
and setAttributeNS( null, ... ) was the preferred approach.

Fast-forward a few years of cargo-culting that approach and this became
firmly entrenched as best practice. Meanwhile tools and language
support have improved. I think it was last year on one of the XML
mailing lists I follow that someone challenged this practice with
examples to back up the fact that many implementations appear to be
consistent that setAttribute( ... ) is the same as
setAttribute( null, ... ).

Hopefully, someone has a definitive answer on this. As I said all I
have are anecdotes, and my (admittedly fuzzy) memory.

 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.  So, as per my oversimplified
 understanding, we use the more arcane construction (and its extra
 seven keystrokes and the extra 80,000 neural synapses) in
 anticipation of such a possible future. I truly don't rue the seven
 keystrokes, as much as all the norepinephrine, seratonin and the like.
 
 So as I say, it is not important that I understand it. There may be, 
 already, a shortage of norepinephrine which would preclude me from
 ever understanding it. But what words might I use to explain this
 oddity to others? If I happen to understand your explanation that
 will be a serendipitous but unexpected side-effect!

G. Wade

-- 
That's what I love about GUIs: They make simple tasks easier, and
complex tasks impossible.
   -- John William Chambless, 39v25i$2...@whale.st.usm.edu




-
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/



Re: [svg-developers] explaining setAttribute, setAttributeNS and carburetors

2010-10-16 Thread Doug Schepers
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/