MSXML2家族探秘

客户端程序编写免不了经常接触XMLHttpRequest对象。
微软的XHR实现的progid又是一串一串的。 烦人。抽一个中午时间,找了找资料,整理记录如下:

"Microsoft.XMLHTTP"
最早的XHR实现。微软官网上说这是MSXML 2.x系列版本的progid。
2.x 系列progid是不带版本号的。看起来简单清楚。
引用内容 引用内容
MSXML 2.6 was shipped with SQL Server 2000 and MDAC 2.6 and is provided in Windows or other service pack updates provided by Microsoft.

MSXML 2.6 installs in replace mode only.

"MSXML2.XMLHTTP"
MSXML 3.0 的progid

"MSXML2.XMLHTTP.3.0"
也是MSXML 3.0 的,应该等价于MSXML2.XMLHTTP;这时,可能是感觉到那种不带版本号的progid,在升级后造成的兼容性问题,以后的更新版本的progid都可以带上版本好吗。
引用内容 引用内容
MSXML 3.0 is provided as a required component with a number of Microsoft products, such as Microsoft Visual Studio and Microsoft Office. It is also a system component for current versions of Microsoft Windows.

MSXML 3.0 SP2 or later installs in replace mode only. (Note: you do not need to run xmlinst.exe utility when updating to this version of MSXML 3.0)

"Msxml2.XMLHTTP.4.0"
此后的版本,都带上了版本号码,可能是为了应对程序员懒散的习惯(不喜欢带那个版本号),不提供以前那种无版本后缀的progid了。
引用内容 引用内容
MSXML 4.0 is a separate download that was released by Microsoft in October 2001. The latest or current service pack release of MSXML 4.0 is available through the Microsoft Web site. MSXML 4.0 must be installed separately and is not currently included with other Microsoft products.

MSXML 4.0 installs side-by-side with earlier versions of MSXML without affecting any existing functionality.

"Msxml2.XMLHTTP.5.0"
引用内容 引用内容
MSXML 5.0 for Microsoft Office Applications is only available with current versions of Microsoft Office.

MSXML 5.0 for Microsoft Office Applications installs side-by-side with earlier versions of MSXML without affecting any existing functionality.

"Msxml2.XMLHTTP.6.0"
引用内容 引用内容
MSXML 6.0 is a separate download that was released by Microsoft in November 2005. The latest or current service pack release of MSXML 6.0 is available through the Microsoft Web site. MSXML 6.0 must be installed separately. It is included with SQL Server 2005.

MSXML 6.0 installs side-by-side with earlier versions of MSXML without affecting any existing functionality.


如何探测
这么多的实现,哪我们如何探测呢?一般来说,我们应该尽量采用更新的更常用的版本。
我的选择是(摘自JSI内核源码):

if(this.ActiveXObject && !this.XMLHttpRequest ){
    var xmlHttpRequstActiveIds = [
        "Microsoft.XMLHTTP"//IE5的,最早的XHR实现
        ,"MSXML2.XMLHTTP"
        //,"MSXML2.XMLHTTP.3.0"//应该等价于MSXML2.XMLHTTP
        //,"Msxml2.XMLHTTP.4.0"
        ,"Msxml2.XMLHTTP.5.0"
        //,"Msxml2.XMLHTTP.6.0"
        ];
    var xmlHttpRequstActiveId
    this.XMLHttpRequest = function(){
        if(xmlHttpRequstActiveId){
            return new ActiveXObject(xmlHttpRequstActiveId);
        }else{
            var i=xmlHttpRequstActiveIds.length;
            while(i --){
                try{
                      var impl = new ActiveXObject(xmlHttpRequstActiveId = xmlHttpRequstActiveIds[i]);
                      xmlHttpRequstActiveIds = null;
                      return impl;
                }catch (e){}
            }
        }
    };
}

参考:
http://msdn2.microsoft.com/en-us/library/ms762757(VS.85).aspx
http://msdn2.microsoft.com/en-us/library/ms761415(VS.85).aspx

评论: 0 | 引用: 0 | 查看次数: 4063
发表评论
登录后再发表评论!