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内核源码)::
js 代码
 
  1. if(this.ActiveXObject && !this.XMLHttpRequest ){  
  2.     var xmlHttpRequstActiveIds = [  
  3.         "Microsoft.XMLHTTP"//IE5的,最早的XHR实现  
  4.         ,"MSXML2.XMLHTTP"  
  5.         //,"MSXML2.XMLHTTP.3.0"//应该等价于MSXML2.XMLHTTP  
  6.         //,"Msxml2.XMLHTTP.4.0"  
  7.         ,"Msxml2.XMLHTTP.5.0"  
  8.         //,"Msxml2.XMLHTTP.6.0"  
  9.         ];  
  10.     var xmlHttpRequstActiveId  
  11.     this.XMLHttpRequest = function(){  
  12.         if(xmlHttpRequstActiveId){  
  13.             return new ActiveXObject(xmlHttpRequstActiveId);  
  14.         }else{  
  15.             var i=xmlHttpRequstActiveIds.length;  
  16.             while(i --){  
  17.                 try{  
  18.                       var impl = new ActiveXObject(xmlHttpRequstActiveId = xmlHttpRequstActiveIds[i]);  
  19.                       xmlHttpRequstActiveIds = null;  
  20.                       return impl;  
  21.                 }catch (e){}  
  22.             }  
  23.         }  
  24.     };  
  25. }  




参考:
http://msdn2.microsoft.com/en-us/library/ms762757(VS.85).aspx
http://msdn2.microsoft.com/en-us/library/ms761415(VS.85).aspx
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值