W
whbell
Unregistered / Unconfirmed
GUEST, unregistred user!
Microsoft.XMLDOM, 为什么我这里使用JavaScript创建XML对象失败,而用VBScript成功?
本地没有安装msxml3_cn.exe,因为不想使得用户必须安装xml3.0
只想利用IE5中的msxml2, 只要个低版本的解析器满足要求就行了。
==============================JavaScript(创建失败的例子)=================================================
<html>
<head></head>
<body>
<script>
function transString(){
//var xd=new ActiveXObject("msxml2.domdocument");
//var xs=new ActiveXObject("msxml2.domdocument");
var xd = ActiveXObject("Microsoft.XMLDOM");
xd.async = False;
var xs = ActiveXObject("Microsoft.XMLDOM");
xs.async = False;
//var xd = CreateObject("Microsoft.XMLDOM");
//var xs = CreateObject("Microsoft.XMLDOM");
try{
xd.loadXML("report.xml");
xs.loadXML("report.xsl");
return xd.transformNode(xs);
}
catch(err){return err.description};
}
function openWin() {
doc = window.document;
axml = transString();
doc.write(axml);
}
</script>
<button onclick="openWin();">Open</button>
</body>
</html>
===============================VBscript(成功的例子)======================================
<html>
<head></head>
<body>
<script language=vbscript>
function TRANS()
Setdo
c = CreateObject("Microsoft.XMLDOM")
do
c.async = False
do
c.load "report.xml"
Set xsls = CreateObject("Microsoft.XMLDOM")
xsls.async = False
xsls.load "report.xsl"
TRANS= do
c.transformNode(xsls)
end function
function Onopen()
set doc = window.document
axml = TRANS()
doc.write(axml)
end function
</script>
<button onclick="Onopen()">Open</button>
</body>
</html>
本地没有安装msxml3_cn.exe,因为不想使得用户必须安装xml3.0
只想利用IE5中的msxml2, 只要个低版本的解析器满足要求就行了。
==============================JavaScript(创建失败的例子)=================================================
<html>
<head></head>
<body>
<script>
function transString(){
//var xd=new ActiveXObject("msxml2.domdocument");
//var xs=new ActiveXObject("msxml2.domdocument");
var xd = ActiveXObject("Microsoft.XMLDOM");
xd.async = False;
var xs = ActiveXObject("Microsoft.XMLDOM");
xs.async = False;
//var xd = CreateObject("Microsoft.XMLDOM");
//var xs = CreateObject("Microsoft.XMLDOM");
try{
xd.loadXML("report.xml");
xs.loadXML("report.xsl");
return xd.transformNode(xs);
}
catch(err){return err.description};
}
function openWin() {
doc = window.document;
axml = transString();
doc.write(axml);
}
</script>
<button onclick="openWin();">Open</button>
</body>
</html>
===============================VBscript(成功的例子)======================================
<html>
<head></head>
<body>
<script language=vbscript>
function TRANS()
Setdo
c = CreateObject("Microsoft.XMLDOM")
do
c.async = False
do
c.load "report.xml"
Set xsls = CreateObject("Microsoft.XMLDOM")
xsls.async = False
xsls.load "report.xsl"
TRANS= do
c.transformNode(xsls)
end function
function Onopen()
set doc = window.document
axml = TRANS()
doc.write(axml)
end function
</script>
<button onclick="Onopen()">Open</button>
</body>
</html>