Adding namespace for VML

R

Robert

I have been doing some successful test with javascript and VML in IE6/7.
The only annoyance I have is that I need a
xmlns:vml="urn:schemas-microsoft-com:vml"
on my HTML element, and the web framework border/template page has no
idea if VML is going to be used.

Is there a way that javascript can add this namespace?
That way I only have the namespace, when VML is going to be used.

Robert
 
B

Bart Van der Donck

Robert said:
I have been doing some successful test with javascript and VML in IE6/7.
The only annoyance I have is that I need a
xmlns:vml="urn:schemas-microsoft-com:vml"
on my HTML element, and the web framework border/template page has no
idea if VML is going to be used.

Is there a way that javascript can add this namespace?
That way I only have the namespace, when VML is going to be used.

That is possible, at least in theory:

var HtmlTagRef = document.getElementsByTagName('HTML')[0]
HtmlTagRef.setAttribute('xmlns:v','urn:schemas-microsoft-com:vml')

It is important that this code is fully loaded and executed before the
VML is invoked. Normally, script code in <head> should be executed
before VML-code in the document body; but I'm not 100% sure about
that.

But my actual question is why you want to avoid

<html xmlns:v="urn:schemas-microsoft-com:vml">

from the start ? This just reserves the "v"-namespace, that's all. It
doesn't harm if it's further used or not.

P.S. http://msdn2.microsoft.com/en-us/library/bb263897.aspx:

| You must also have the following in your STYLE element to register
| the behavior of VML and Microsoft Office Extensions. If you are
| not using Office Extensions, you can omit the second behavior
| definition.
| v\:* { behavior: url(#default#VML); display:inline-block}
| o\:* { behavior: url(#default#VML); }

Hope this helps,
 
R

Robert

Bart said:
Robert said:
Is there a way that javascript can add this namespace?
That way I only have the namespace, when VML is going to be used.

That is possible, at least in theory:

var HtmlTagRef = document.getElementsByTagName('HTML')[0]
HtmlTagRef.setAttribute('xmlns:v','urn:schemas-microsoft-com:vml')

Alas! It has no effect :(
It is important that this code is fully loaded and executed before the
VML is invoked. Normally, script code in <head> should be executed
before VML-code in the document body; but I'm not 100% sure about
that.

I have no VML-code in my body.
The VML is added later dynamically. It works well with the namespace.
Executing the setAttribute before doing anything with VML has no effect.

One thing I noticed with the IE developer toolbar that specifying a
namespace on the html element is not reflected on the attributes view if
the developer toolbar.
However when using the setAttribute I can see it there.
But my actual question is why you want to avoid

<html xmlns:v="urn:schemas-microsoft-com:vml">

from the start ? This just reserves the "v"-namespace, that's all. It
doesn't harm if it's further used or not.

It is just an annoyance. No big thing (probably). But was trying to see
if I could do something more clean.
 
B

Bart Van der Donck

Robert said:
That is possible, at least in theory:
var HtmlTagRef = document.getElementsByTagName('HTML')[0]
HtmlTagRef.setAttribute('xmlns:v','urn:schemas-microsoft-com:vml')

Alas! It has no effect :(

I'm not sure how you tested that; the following seems to work fine
here on XP MSIE6 and Vista MSIE7:

<html>
<head>
<style>
v\:* { behavior: url(#default#VML);}
o\:* { behavior: url(#default#VML);}
</style>
<title>VML Sample</title>
</head>
<body>
<script type="text/javascript">
var HtmlTagRef = document.getElementsByTagName('HTML')[0]
HtmlTagRef.setAttribute('xmlns:v','urn:schemas-microsoft-com:vml')
document.write('<v:shape\n')
document.write('fillcolor="red"\n')
document.write('style="width:200px;height:150px"\n')
document.write('path = "m 1,1 l 1,200, 200,200, 200,1 x e">\n')
document.write('</v:shape>\n')
</script>
</body>
I have no VML-code in my body.
The VML is added later dynamically. It works well with the namespace.

Yes, but you should apply the required CSS profile(s) too.
Executing the setAttribute before doing anything with VML has no effect.

See example page above.
One thing I noticed with the IE developer toolbar that specifying a
namespace on the html element is not reflected on the attributes view if
the developer toolbar.

Maybe because the attribute was added later dynamically ?
However when using the setAttribute I can see it there.

Yes, the attribute ought to be inserted correctly to the DOM.
It is just an annoyance. No big thing (probably). But was trying to see
if I could do something more clean.

I think the cleanest is certainly to use

<html xmlns:v="urn:schemas-microsoft-com:vml">

from the start without further trickery.
 
R

Robert

Bart said:
Robert said:
Bart said:
Robert wrote:
Is there a way that javascript can add this namespace?
That way I only have the namespace, when VML is going to be used.
That is possible, at least in theory:
var HtmlTagRef = document.getElementsByTagName('HTML')[0]
HtmlTagRef.setAttribute('xmlns:v','urn:schemas-microsoft-com:vml')
Alas! It has no effect :(

I'm not sure how you tested that; the following seems to work fine
here on XP MSIE6 and Vista MSIE7:

I use the DOM to add the VML elements:

var rect = document.createElement("v:rect")
....
parent.appendChild(rect); //error without namespace

Yes, but you should apply the required CSS profile(s) too.

Of course. Otherwise it would never work.
Maybe because the attribute was added later dynamically ?

No. If the namespace is statically specified on the html element, then
the attributes view does not show it.
 
D

David Mark

Robert said:
Bart Van der Donck wrote:
Robert wrote:
Is there a way that javascript can add this namespace?
That way I only have the namespace, when VML is going to be used.
That is possible, at least in theory:
var HtmlTagRef = document.getElementsByTagName('HTML')[0]
HtmlTagRef.setAttribute('xmlns:v','urn:schemas-microsoft-com:vml')
Alas! It has no effect :(

I'm not sure how you tested that; the following seems to work fine
here on XP MSIE6 and Vista MSIE7:

It doesn't work as IE's implementation of setAttribute is incorrect.
The above is equivalent to:

HtmlTagRef['xmlns:v'] = 'urn:schemas-microsoft-com:vml';

So it just creates a new property.
<html>
<head>
<style>
v\:* { behavior: url(#default#VML);}
o\:* { behavior: url(#default#VML);}
</style>
<title>VML Sample</title>
</head>
<body>
<script type="text/javascript">
var HtmlTagRef = document.getElementsByTagName('HTML')[0]
HtmlTagRef.setAttribute('xmlns:v','urn:schemas-microsoft-com:vml')

It works in IE7 as well, even if you comment out that line.
document.write('<v:shape\n')
document.write('fillcolor="red"\n')
document.write('style="width:200px;height:150px"\n')
document.write('path = "m 1,1 l 1,200, 200,200, 200,1 x e">\n')
document.write('</v:shape>\n')
</script>
</body>



Yes, but you should apply the required CSS profile(s) too.


See example page above.


Maybe because the attribute was added later dynamically ?

It never shows up as an attribute.
Yes, the attribute ought to be inserted correctly to the DOM.

It would be if IE had a working setAttribute method. I don't know if
it would have any effect on the problem though.
I think the cleanest is certainly to use

<html xmlns:v="urn:schemas-microsoft-com:vml">

from the start without further trickery.

It seems the only option. Though you could use outerHTML to insert
the attribute after the page loads, I am not sure if it would have any
effect at that point.
 

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

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top