js解析XMlファイルは、IE、Firefox、Googleに対応しています.
8917 ワード
[javascript] view plain copy
loadXML = function(xmlFile){
var xmlDoc=null;
var agent = navigator.userAgent.toLowerCase();
//
// IE
if(agent.indexOf("msie") > 0){
alert("22");
var xmlDomVersions = ['MSXML.2.DOMDocument.6.0','MSXML.2.DOMDocument.3.0','Microsoft.XMLDOM'];
for(var i=0;i){
try{
xmlDoc = new ActiveXObject(xmlDomVersions[i]);
break;
}catch(e){
}
}
}
// firefox
else if(agent.indexOf("firefox") > 0){
try{
xmlDoc = document.implementation.createDocument('','',null);
}catch(e){
}
} else{
//
alert("111111111");
var oXmlHttp = new XMLHttpRequest() ;
oXmlHttp.open( "GET", xmlFile, false ) ;
oXmlHttp.send(null) ;
return oXmlHttp.responseXML;
}
if(xmlDoc!=null){
xmlDoc.async = false;
xmlDoc.load(xmlFile);
}
return xmlDoc;
}
$(function(){
var bankDoc = loadXML("bank.xml");
var list = bankDoc.getElementsByTagName("bank");
$("BankID").length = 0;
for (var i = 0; i < list.length; i++) {
bankId = list[i].getAttribute("bankId");
bankName = list[i].getAttribute("bankName");
alert(bankName);
}
});
xmlファイル:[html] view plain copy
xml version="1.0" encoding="UTF-8" ?>
<Items>
<bank bankId="" bankName=" " />
<bank bankId="100" bankName=" " />
<bank bankId="102" bankName=" " />
<bank bankId="103" bankName=" " />
<bank bankId="104" bankName=" " />
<bank bankId="105" bankName=" " />
<bank bankId="301" bankName=" " />
<bank bankId="302" bankName=" " />
<bank bankId="303" bankName=" " />
<bank bankId="304" bankName=" " />
<bank bankId="305" bankName=" " />
<bank bankId="306" bankName=" " />
Items>
自分で測ってie 8、Firefox、chrome、携帯qqブラウザを支持します.転載元:http://blog.csdn.net/u283056051/article/details/49254777
転載先:https://www.cnblogs.com/lxgandlz/p/5447095.html