查看: 5959|回复: 0
打印 上一主题 下一主题

建立MS XML 测试环境

[复制链接]
跳转到指定楼层
1#
发表于 2008-2-21 13:59:41 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
台州网址导航
一般的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方式安装.
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播 分享分享 分享淘帖
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

网站推广
关于我们
  • 台州朗动科技(Tzweb.com)拥有多年开发网站平台系统门户手机客户端等业务的成功经验。主要从事:政企网站,系统平台,微信公众号,各类小程序,手机APP客户端,浙里办微应用,浙政钉微应用、主机域名、虚拟空间、后期维护等服务,满足不同企业公司的需求,是台州地区领先的网络技术服务商!

Hi,扫描关注我

Copyright © 2005-2026 站长论坛 All rights reserved

Powered by 站长论坛 with TZWEB Update Techonolgy Support

快速回复 返回顶部 返回列表