By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,420 Members | 1,248 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,420 IT Pros & Developers. It's quick & easy.

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

P: n/a
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');

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

Does anyone have any suggestions for how to either get this value, or
perhaps another way to validate that the VML ns has been installed?

Feb 1 '07 #1
Share this Question
Share on Google+
2 Replies

P: n/a
VK
On Feb 1, 8:11 pm, "aglaforge" <aglafo...@gmail.comwrote:
<!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" ? <htmltag 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 <htmland 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
<htmlelement 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 :-)
Feb 1 '07 #2

P: n/a
On Feb 1, 12:28 pm, "VK" <schools_r...@yahoo.comwrote:
On Feb 1, 8:11 pm, "aglaforge" <aglafo...@gmail.comwrote:
<!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" ? <htmltag 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 <htmland 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
<htmlelement 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!

Feb 1 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.