动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   Xml → 阅读文章

 建立MSXML 测试环境

作者来源: 
阅读 2437 人次 , 2006-2-16 14:45:00 

一般的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方式安装。

引自:http://hi-blue.com/technology/article/2157.asp

  
 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:XSL-FO 学习笔记
· 下一篇:XML加ASP实现网页“本地化”
· XML简易教程之一
· XML与HTML的结合(下)
· 用asp.net和xml做的新闻更新系统(3)
· 用C#与XML创建动态分层菜单
· PHP 和 XML: 使用expat函数(二)


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077