在 HTMLDocument 解析器中禁用 VML 支持

Disabling VML support in HTMLDocument parser

我正在解析和处理由 Word 创建的现有 HTML 文件(无法重新创建这些文件)。 HTML 带有嵌入图像的文件包括用于启用 vml 的浏览器的条件格式,类似于以下内容:

     <!--[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]>

我将 HTML 文件加载到 IHTMLDocument2 对象的一个​​实例中。由于IE支持VML,它解析出上面的<img>标签,只留下shapeimagedata标签。我宁愿忽略所有特定于 vml 的标签,只使用 <img> 标签。

有没有办法以编程方式禁用 VML 支持(类似于 IHTMLDocument2.desgnMode = "On" 禁用脚本)?

Word 生成的内容称为 "Conditional comments"。更具体地说,我们这里 "Downlevel-hidden conditional comments" 采用以下形式:

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

expression 使用运算符和 "Version vectors"。 一般来说,这些向量指的是"IE",用来处理HTML compatiblity issues.

但您可以使用自定义版本向量:

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]-->

由于 VML 本身是一个(嵌入式)附加组件,您可以在 64 位 OS [=15] 上使用 HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Version Vector\VML 键 and/or 32 位键=].显然,完全删除密钥可以解决您的问题。