javascript - Correct way to get value of namespace declaration attribute -


consider svg/xml , javascript:

<svg id="foo" xmlns="http://www.w3.org/2000/svg"               xmlns:xlink="http://www.w3.org/1999/xlink">   <use id="bar" xlink:href="#whee" /> </svg> ... var foo  = document.getelementbyid('foo'); var bar  = document.getelementbyid('bar'); var xlnk = foo...; // correct here? var link = bar.getattributens(xlnk,'href'); 

clearly can make work xlnk = "http://www.w3.org/1999/xlink"; question, however, correct way dynamically fetch xmlns:xlink attribute on svg element?

the following code happens work in safari/chrome/ff, valid?
var xlnk = foo.getattribute('xmlns:xlink');

the following code returns empty string in browsers:
var xlnk = foo.getattributens( "http://www.w3.org/2000/svg", "xlink" );

the getattributens() specification documents second parameter as:

"the local name of attribute retrieve."

per namespaces in xml, 3rd edition xmlns prefix reserved , used part of prefixedattname define nsattname.

since nsattname not have "local part"—and qname does—it seems xmlns:xlink not considered namespace+local name, rather attribute name itself. consistent experimental results across normally-standards-compliant browsers, convinced following code valid , correct:

var xlnk = foo.getattribute('xmlns:xlink'); 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -