
























XML引擎版本的不同,给程序设计带来诸多不便。将常见的几个版本来个遍历检测,就能自动适应了。
<script language="JavaScript">
var objXML;
function findXMLVersion() {
var xmlVersion = ["4.0", "3.0", "2.6", "2.5", "2", "Microsoft", "MSXML"];
var xmlDoc = "hellow World";
var i, objXml, objXmlDom, strRetVal="";
for (i=0; i <= xmlVersion.length-1; i++) {
if (xmlVersion[i] == "Microsoft") {
try {
objXML = new ActiveXObject("Microsoft.XMLDOM");
objXML.async = false;
if (objXML.loadXML(xmlDoc)) {
if (strRetVal == "") strRetVal = "Microsoft";
}
} catch (e)
{ }
}
else if (xmlVersion[i] == "MSXML") {
try {
objXML = new ActiveXObject("Msxml.DOMDocument");
objXML.async = false;
if (objXML.loadXML(xmlDoc)) {
if (strRetVal == "") strRetVal = "Msxml";
}
} catch (e)
{ }
}
else if (xmlVersion[i] == "2") {
try {
objXML = new ActiveXObject("Msxml2.DOMDocument");
objXML.async = false; if (objXML.loadXML(xmlDoc)) {
if (strRetVal == "")
strRetVal = "Msxml2";
}
}
catch (e)
{ }
}
else {
try {
objXML = new ActiveXObject("Msxml2.DOMDocument." + xmlVersion[i]);
objXML.async = false;
if (objXML.loadXML(xmlDoc)) {
if (strRetVal == "")
strRetVal = "Msxml2";
}
}
catch (e)
{ }
}
}
return strRetVal;
}
findXMLVersion();
XMLTest();
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。