Extracting the xmlns:v attribute out of an HTML element in IE?

A

aglaforge

I'm attempting to write a quick piece of Javascript code that will
validate if the end user of the javascript has the necessary VML
attributes set in their HTML. The problem in IE is that "xmlns:v"
does not appear in their attributes property or the
getAttribute('xmlns:v') calls. The real kicker is that the 'xmlns'
attribute does return something.

The HTML Snippet would look like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-
microsoft-com:vml" anthony="abc">
<head>

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

var htmlElement = window.top.document.getElementsByTagName("html")[0];

//Returns "http://www.w3.org/1999/xhtml" Expected "http://www.w3.org/
1999/xhtml"
var validAttr = htmlElement.getAttribute('xmlns');

//Returns "" Expected "urn:schemas-microsoft-com:vml"
var badAttr = htmlElement.getAttribute('xmlns:v');
 
V

VK

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-
microsoft-com:vml" anthony="abc">
<head>

a side note: what is anthony="abc" ? <html> tag is not a place for
copyrigths, memos or quick notes ;-) Except namespaces and maybe lang
anything else out, no matter what different specs may say.

Now:
by Mycrosoft HTML has default namespace and it is called "HTML"; also
IE knows nothing about XHTML.
This way ...html xmlns="http://www.w3.org/1999/xhtml"... is simply
ignored by error correction mechanics so <html> and all other tags
without namespace prefix will stay in the default "HTML" namespace,
that will be happily reported by anyone of them if you ask to, say:
alert( document.getElementsByTagName('head')[0].scopeName )

....xmlns:v="urn:schemas-microsoft-com:vml"...
adds new "v" namespace, so any element prefixed by v: will be counted
as appertaining to this namespace; but obviously it doesn't affect
<html> element itself - it remains in the default namespace - thus
there is no use to harass it :). All registered namespaces are stored
in document.namespaces collection, all unknown namespaces reported as
null. This way the check is as easy as:
if (document.namespaces['v'] == null) {
// needed xmlns is missing
}

P.S. Just in case a reminder: in Microsoft model xmlns doesn't impose
any predefined formatting or behavior on involved elements. It only
instructs the parser to exclude properly prefixed elements from the
standard "skip unknown tag" error correction mechanics, as it would be
with some <aaa>foobar</aaa>.
On the second necessary step you have to add implementation or
behavior to this namespace.

P.P.S. Funny enough this junky pseudo-xhtml combo above - if served as
text/html - is fully compatible with both W3C and Microsoft models
plus makes Validator all green of hapiness. I'm using this trick too
occasionally when I need to satisfy standards-shifted clients. With
all fixes hidden into conditional CSS: " see it works on IE, see it
works on Gecko, see it validates on*strict* **XHTML** " Works like a
charm :)
 
A

aglaforge

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-
microsoft-com:vml" anthony="abc">
<head>

a side note: what is anthony="abc" ? <html> tag is not a place for
copyrigths, memos or quick notes ;-) Except namespaces and maybe lang
anything else out, no matter what different specs may say.

Now:
by Mycrosoft HTML has default namespace and it is called "HTML"; also
IE knows nothing about XHTML.
This way ...html xmlns="http://www.w3.org/1999/xhtml"... is simply
ignored by error correction mechanics so <html> and all other tags
without namespace prefix will stay in the default "HTML" namespace,
that will be happily reported by anyone of them if you ask to, say:
alert( document.getElementsByTagName('head')[0].scopeName )

...xmlns:v="urn:schemas-microsoft-com:vml"...
adds new "v" namespace, so any element prefixed by v: will be counted
as appertaining to this namespace; but obviously it doesn't affect
<html> element itself - it remains in the default namespace - thus
there is no use to harass it :). All registered namespaces are stored
in document.namespaces collection, all unknown namespaces reported as
null. This way the check is as easy as:
if (document.namespaces['v'] == null) {
// needed xmlns is missing
}

P.S. Just in case a reminder: in Microsoft model xmlns doesn't impose
any predefined formatting or behavior on involved elements. It only
instructs the parser to exclude properly prefixed elements from the
standard "skip unknown tag" error correction mechanics, as it would be
with some <aaa>foobar</aaa>.
On the second necessary step you have to add implementation or
behavior to this namespace.

P.P.S. Funny enough this junky pseudo-xhtml combo above - if served as
text/html - is fully compatible with both W3C and Microsoft models
plus makes Validator all green of hapiness. I'm using this trick too
occasionally when I need to satisfy standards-shifted clients. With
all fixes hidden into conditional CSS: " see it works on IE, see it
works on Gecko, see it validates on*strict* **XHTML** " Works like a
charm :)

That's help alot, thank you very much!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top