Disabling VML support in HTMLDocument parser

485 views Asked by At

I am parsing and massaging existing HTML files created by Word (the files cannot be recreated). The HTML files with embedded images include conditional formatting for the vml enabled browsers similar to the following:

     <!--[if gte vml 1]>
     <v:shape
     id="_x0000_i1042" type="#_x0000_t75" style='width:24pt;height:24pt'>
     <v:imagedata src="test_files/image002.png" o:title="Text-HighlightColor-icon_32x32"/>
    </v:shape>
    <![endif]-->
    <![if !vml]>
    <img width=32 height=32 src="test_files/image002.png" v:shapes="_x0000_i1042">
    <![endif]>

I load the HTML file into an instance of the IHTMLDocument2 object. Since IE supports VML, it parses out the <img> tag above leaving only shape and imagedata tags. I would prefer to ignore all vml specific tags and work only with the <img> tag.

Is there any way to disable the VML support (similar to IHTMLDocument2.desgnMode = "On" to disable scripts) programmatically?

1

There are 1 answers

0
Simon Mourier On BEST ANSWER

What Word generates is called "Conditional comments". More specifically, we have here "Downlevel-hidden conditional comments" which take the following form:

<!--[if expression]> HTML <![endif]-->

The expression uses operators and "Version vectors". In general, these vectors refer to "IE" and are used to handle HTML compatiblity issues.

But you can use custom version vectors:

If you develop add-ons, you can use custom version vectors to provide version information to webpages. To define a custom version vector, add a REG_SZ value to the Version Vector Registry key. The name of the new key defines the feature value to use in a conditional comment, as shown here.

HKEY_LOCAL_MACHINE
   Software
      Microsoft
         Internet Explorer
            Version Vector
               Contoso = 0.9

The previous example uses a custom version vector to indicate that a pre-release version (0.9) of the fictional Contoso control is installed on a user's computer. This next example shows how a conditional comment might use this information.

<!--[if lt Contoso 2]>
<p>Your version of the Contoso control is out of date; Please update to the latest.</p>
<![endif]-->

Since VML is itself an (embedded) add-on, you can play with HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Version Vector\VML key and/or the 32-bit one on a 64-bit OS HKEY_LOCAL_MACHINE\Software\WOW6432Node\Microsoft\Internet Explorer\Version Vector\VML. Apparently, completely deleting the key fixed your problem.