当前位置: 首页 > 图文教程 > 网络编程 > ASP > 建立MSXML 测试环境

ASP
ASP实现不存在的网页就自动发送邮件
多个绑定多域名的ASP代码
ASP导出Excel数据的四种方法
用控件的方式解决问题-在客户端关联WEB控件引用
用ASP建立一个简单的聊天室
用Asp隐藏文件路径,实现防盗链
ASP实例:即时显示当前页面浏览人数
网页视频播放器程序代码通用代码
Cookies 欺骗漏洞的防范(vbs+js 实现)
ASP应用程序设计的Web状态管理分析
ASP中Session技巧
ASP教程:透彻掌握ASP分页技术
ASP获取字符串长度的自定义函数
通过实例讲解来学习ASP中的函数
ASP实例代码:长文章分页代码设置方法
深入理解ASP中FSO的神奇功能
用ASP代码得到客户端IP和当前地址
服务端 VBScript 与 JScript 几个相同特性的写法
JS+DIV模拟SELECT表单域
插入ASP代码让网站数据库成为ASP木马

ASP 中的 建立MSXML 测试环境


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 28 ::
收藏到网摘: n/a

      
  一般的Windows环境(Windows 98 SE以上版本)都有一个MSXML环境,以下的asp代码可以运行,但不一定工作,不工作可能是由于样式单是http://www.w3.org/1999/XSL/Transform的,而最初环境只支持http://www.w3.org/TR/WD-xsl,所以可能什么也不出来。
  
  <%@ LANGUAGE = JScript %>
  <%
  // Set the source and style sheet locations here
  var sourceFile = Server.MapPath("test.xml");
  var styleFile = Server.MapPath("test.xsl");
  
  // Load the XML
  var source = Server.CreateObject("Microsoft.XMLDOM");
  source.async = false;
  source.load(sourceFile);
  // Load the XSL
  var style = Server.CreateObject("Microsoft.XMLDOM");
  style.async = false;
  style.load(styleFile);
  Response.Write(source.transformNode(style));
  %>
  
  一般以MSXML为开发环境的都要建立安装新的解析器,如MSXML 3或者MSXML 4 Technology Preview,
  在以replace方式装了MSXML 3后,我们可以使用以下的代码
  
  <%@ LANGUAGE = JScript %>
  <%
  // Set the source and style sheet locations here
  var sourceFile = Server.MapPath("test.xml");
  var styleFile = Server.MapPath("test.xsl");
  
  // Load the XML
  var source = Server.CreateObject("Msxml2.DOMDocument");
  source.async = false;
  source.load(sourceFile);
  // Load the XSL
  var style = Server.CreateObject("Msxml2.DOMDocument");
  style.async = false;
  style.load(styleFile);
  Response.Write(source.transformNode(style));
  %>
  
  这样我们获得了MSXML 3的开发环境,但如果我们不想破坏原来的环境,又要测试我们基于MSXML 3的例子呢,虽然用replace方式安装提供了向后兼容方式来支持XSL元素,函数和XSL命名空间。
  
  其实使用版本无关progIDs(version-dependent progIDs)来创建对象实例可以更好的完成工作,我们不需要用replace方式安装,用side-by-side方式即可,我们看下面的代码:
  
  <%@ LANGUAGE = JScript %>
  <%
  // Set the source and style sheet locations here
  var sourceFile = Server.MapPath("test.xml");
  var styleFile = Server.MapPath("test.xsl");
  
  // Load the XML
  var source = Server.CreateObject("Msxml2.DOMDocument.3.0");
  source.async = false;
  source.load(sourceFile);
  // Load the XSL
  var style = Server.CreateObject("Msxml2.DOMDocument.3.0");
  style.async = false;
  style.load(styleFile);
  Response.Write(source.transformNode(style));
  %>
  
  只需要在Msxml2.DOMDocument后面加上版本号3.0,即可使用MSXML 3的东东了,MSXML 4呢,依次类推。
  
  
  在客户端的环境也是一样的,用js创建DOM对象是一样的。
  
  function test(){
  var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
  var currNode;
  xmlDoc.async = false;
  xmlDoc.load("test.xml");
  currNode = xmlDoc.documentElement.firstChild;
  alert(currNode.xml);
  }
  
  最后,XSLT样式单side-by-side方式下在Internet Explorer 5.0及以后版本不支持。如果你要使用IE 5来打开XSLT样式单,需要用replace方式安装。