http://www.cnblogs.com/mjgforever/archive/2007/08/31/877076.html
前言
微软有很多MSXML的版本,如Msxml2.DOMDocument.6.0、Msxml2.DOMDocument.5.0、Msxml2.DOMDocument.4.0等。在浏览器中如何运用这些版本显得非常必要。
常见的错误用法:
if (Web.Application.get_type() == Web.ApplicationType.InternetExplorer) {
var progIDs = [ 'Msxml2.DOMDocument.6.0', 'Msxml2.DOMDocument.5.0', 'Msxml2.DOMDocument.4.0', 'Msxml2.DOMDocument.3.0', 'Msxml2.DOMDocument' ]; // MSXML5.0, MSXML4.0 and Msxml2.DOMDocument all have issues - be careful when using. Details below.
for (var i = 0; i < progIDs.length; i++) {
try {
var xmlDOM = new ActiveXObject(progIDs[i]);
return xmlDOM;
}
catch (ex) {
}
}
return null;
}
http://blogs.msdn.com/xmlteam/archive/2006/10/23/using-the-right-version-of-msxml-in-internet-explorer.aspx
The code iterates through the "progIDs" array and instantiates the highest version MSXML DOM that is available on the machine and returns it to the caller (see below for details on which versions ship where). This has at least a few implications:
-
Compatibility – We do our best to maintain compatibility across versions of MSXML, however earlier versions of MSXML like MSXML 3 and MSXML 4 were implemented during the “wild west” of the XML emergence and we’ve learned a lot since then. In addition, MSXML5 for Microsoft Office Applications was targeted specifically at Office scenarios. Sometimes we do need to make design or implementation changes that affect behavior across MSXML versions. By iterating through the versions of MSXML you open your app up to more potential risk of “finding” one of the differences unexpectedly.
-
Robustness - We can't fix every bug in every version so we've targeted MSXML6 (our newest) and MSXML3 (our most broadly deployed) versions of MSXML where we'll make the biggest investments.
-
Test cost – The more versions of MSXML your application potentially depends on means more versions to test your application with before you can ship it to your customers.
My goal for this post is to give a quick history of MSXML lifecycle and versions, provide details with an example on implementing best practices with MSXML on the web, and talk about a couple key things to watch out for.
If you want the full story please read on, but if you’re short on time and want the quick scoop here it is in 4 bullets:
-
Use MSXML 6.0 - it is “in the box” on Vista and available for download on Win2k, XP, and 2003. It has the best security, performance, reliability, and W3C conformance
-
MSXML 3.0 is our preferred “fallback” -It is installed on every OS from a fully patched Win2k SP4 installation on up, so it requires “zero-deployment” and is serviced regularly with the OS
-
MSXML 4.0 was released to the web about 5 years ago, but at this point has been superseded by MSXML 6.0 and is only intended to support legacy applications
-
MSXML 5.0 for Microsoft Office Applications is purpose-built for Office applications and isn’t intended for broad deployment. Internet Explorer 7 actually has the MSXML5 components "off-by-default" in the Internet zone so your customers will get a goldbar for each MSXML5 control on a page if your code tries to instantiate it. The best recommendation is to avoid MSXML5 in your web apps (only machines with Office 2003 or higher will have it, anyway.).
MSXML Lifecycle & History
OK, the full story requires a little bit more context – so let’s cover the different versions of MSXML, where they ship, and what the long term strategy is.
Over the long run, the goal is to have our customers move their applications to MSXML6. In terms of deployment, we want to ship our technology "in-the-box" with the operating system so that page authors and app developers can take advantage of it with zero deployment. However, our customers have told us they want symmetrical XML APIs on all supported OS platforms, so we still need a way to get the newest XML technologies to our downlevel OSes (Win2k, Win XP, and Win 2k3).
MSXML6 will be part of the Vista operating system when it releases, but requires a redistributable package to be installed downlevel. We’d like to get MSXML6 “inlined” in the next service pack of each of the downlevel OSes, but we need a strong business case to do so. So in the short and medium term we will continue to ship a redistributable package for MSXML6 that can be installed on downlevel operating systems. We'll try to get a post up on the benefits of moving to MSXML6 sometime soon.
As much as we'd love everyone to be on MSXML6 today, we realize the migration can take some time. So we're continuing to invest in MSXML3 to support existing applications and applications that have zero deployment requirements. MSXML3 doesn't have all the improvements in MSXML6, but developers should consider it a robust and stable platform for MSXML applications. MSXML3 is already part of the operating system on a fully patched Win2k SP4 installation and higher so in general no deployment to the client is required. Going forward, MSXML3 updates will come out in each of the OS service packs. MSXML3 SP7 is the last update to MSXML3 that should ship in redistributable form and in the future no redistributable package should be necessary for our partners and customers to use MSXML3 functionality.
Finally, anyone using MSXML5 who isn’t writing applications specifically targeted at Microsoft Office 2003 or Microsoft Office 2007 should migrate to MSXML6.
The details
Once you pick a version of MSXML to use, how do you do it effectively? MSXML ships side-by-side with version dependent ProgIDs. That means two things:
var xmlDOM = new ActiveXObject('Msxml2.DOMDocument.3.0') //uses MSXML 3.0
var xmlDOM = new ActiveXObject('Msxml2.DOMDocument.6.0') //uses MSXML 6.0
One related note - service packs of a particular version of MSXML are not side by side and will upgrade that version of MSXML to the service pack version. For example, if your computer is running MSXML3 SP5 and you install MSXML3 SP7, all applications that use MSXML3 will automatically be upgraded to run on 3 SP7.
Ideally, customers should standardize on MSXML6, but as mentioned above legacy applications or zero-deployment requirements may block full migration to MSXML6 in the short run. In this case there are two tensions that need to be balanced – functionality and test costs. This essentially leads to two options:
-
Try MSXML6 and fallback to MSXML3 – MSXML6 has some improvements that aren’t in MSXML3 such as support for XSD schema, and improved stability, performance, and security. So your app may try out MSXML6 if it is on the box and then “fallback” gracefully. Just remember to test your app with MSXML6 and with MSXML3 so you aren’t surprised when you release your application. Here’s a quick example:
if (Web.Application.get_type() == Web.ApplicationType.InternetExplorer) {
var progIDs = [ 'Msxml2.DOMDocument.6.0', 'Msxml2.DOMDocument.3.0'];
for (var i = 0; i < progIDs.length; i++) {
try {
var xmlDOM = new ActiveXObject(progIDs[i]);
return xmlDOM;
}
catch (ex) {
}
}
return null;
}
-
Standardize on MSXML3 with an eye towards MSXML6 in the future – This limits functionality somewhat to what is in MSXML3 but also keeps down test costs. I’ll try to post something in the future about writing MSXML3 apps that should upgrade more easily to MSXML6 (and beyond).
A couple things to watch out for
var xmlDOM = new ActiveXObject('Msxml2.DOMDocument.3.0')
and
var xmlDOM = new ActiveXObject('Msxml2.DOMDocument')
-
Older ProgIDs - Stay away from ProgIDs that end in suffixes lower than “3.0”. In particular some older operating systems have MSXML 2.6 on them, however these ProgIDs are “kill-bitted” in the recent MS06-061 Security patch
-
MSXML2 vs. Microsoft namespace – I’ve also seen a lot of code that instantiates the “Microsoft.XMLHTTP” ActiveX object rather than the MSXML2.XMLHTTP.3.0 or MSXML2.XMLHTTP.6.0 if you’re using 6.0. The “Microsoft” namespace is actually older and is only implemented in MSXML3 for legacy support. It’s unfortunate we used the “better” name on the older version, but stick to the “msxml2” namespace when instantiating objects.
As always, I'd love to get some feedback from people so if you have questions, comments, or random thoughts you'd like to share please comment here or mail me directly (email link above).
Adam Wiener
Lead Program Manager
Data Programmability/XML Technologies
分享到:
相关推荐
msxml5.0_23951.rar
再运行测试createobject("msxml2.serverxmlhttp.5.0")通过即msxml5安装正确。 msxml5.dll和msxml5r.dll是office提供的。 5.0 (office 2003) msxml5.dll、msxml5r.dll (5.0.2916.0)(最后一个 dll 是纯资源 dll)...
再运行测试createobject("msxml2.serverxmlhttp.5.0")通过即msxml5安装正确。 msxml5.dll和msxml5r.dll是office提供的。 5.0 (office 2003) msxml5.dll、msxml5r.dll (5.0.2916.0)(最后一个 dll 是纯资源 dll)...
MSXML3 是微软出品的用于解析XML的组件。 此组件基于COM可以被IE调用。 依靠这个组件,你的IE才可以正确的浏览XML文件。 解决MSN在2003上无法登陆方案之一
Office2010安装需要MSXML版本6.10.1129.0,这个错误是缺少msxml文件,上面是下载连接。安装教程 https://jingyan.baidu.com/article/a948d6517babeb0a2ccd2e71.html
msxml4- Windows系统Msxml4安装包,在其他软件需要但系统内并未正确安装的时候可以用来重新安装。
经查询,得知是因为该文件msxml6.msi没有正常安装,可以打开CAD2008安装包,找到\support\msxml\子目录,双击其中的“msxml6.msi”文件重新安装。启动AutoCAD,一切正常!(有的安装包中没有该文件,故笔者上传到此...
用XMLHTTP Post Form时的表单乱码有两方面的原因——Post表单数据时中文乱码;服务器Response被XMLHTTP不正确编码引起的乱码。... var oReq = new ActiveXObject(“MSXML2.XMLHTTP”); oReq.open(“POST”,”h
A6软件表单制作的错误修正,正确下载msxml插件
该编辑器对中文的支持良好,可以极快的速度加载 XML 文档,并生成可自定义的树视图以显示 XML 文档的数据结构(非常有特色,为其他 XML 编辑器所无),可以调用 MSXML 分析引擎验证 XML 文档的正确性和有效性。...
Ajax技术的核心是XMLHttpRequest对象(简称XHR),IE5是第一款引入XHR对象的浏览器,而IE5中的XHR对象是通过MSXML库中的一个ActiveX对象实现的,因此在IE中可能有3个版本,即MSXML2.XMLHttp、MSXML2.XMLHttp.3.0和...
该编辑器对中文的支持良好,可以高速加载XML文档,并生成可自定义的树视图以显示 XML 文档的数据结构(非常有特色,为其他 XML 编辑器所无),可以调用 MSXML 分析引擎验证 XML 文档的正确性和有效性。其独特的 FOAL...
该编辑器对中文的支持良好,可以高速加载XML文档,并生成可自定义的树视图以显示 XML 文档的数据结构(非常有特色,为其他 XML 编辑器所无),可以调用 MSXML 分析引擎验证 XML 文档的正确性和有效性。其独特的 FOAL...
该编辑器对中文的支持良好,可以极快的速度加载 XML 文档,并生成可自定义的树视图以显示 XML 文档的数据结构(非常有特色,为其他 XML 编辑器所无),可以调用 MSXML 分析引擎验证 XML 文档的正确性和有效性。...
该编辑器对中文的支持良好,可以极快的速度加载 XML 文档,并生成可自定义的树视图以显示 XML 文档的数据结构(非常有特色,为其他 XML 编辑器所无),可以调用 MSXML 分析引擎验证 XML 文档的正确性和有效性。
2:针对网上的其它实例增加实时更新IP地址功能,防止断网重连后IP地址显示不正确 3:增加一条命令,用来解决MSXML2.XMLHTTP和Microsoft.XMLHTTP老是读旧缓存导致IP地址无论如何刷新都无变化的问题 4:代码里都有详细...
该编辑器对中文的支持良好,可以高速加载XML文档,并生成可自定义的树视图以显示 XML 文档的数据结构(非常有特色,为其他 XML 编辑器所无),可以调用 MSXML 分析引擎验证 XML 文档的正确性和有效性。其独特的 FOAL...
DTD是一种保证XML文档格式正确的有效方法,可以比较XML文档和DTD文件来看文档是否符合规范,元素和标签使用是否正确。一个DTD文档包含:元素的定义规则,元素间关系的定义规则,元素可使用的属性,可使用的实体或...
1.MSXML2.XMLHTTP更换成MSXML2.ServerXMLHTTP,防止采集或生成首页静态页会卡死问题 2.纠正采集的图片标签中有js脚本时,可能会造成图片获取不到的BUG 3.友情链接管理,到期日期加入快捷的1、3、6、12个月的选择按钮...