日期:2014-05-16  浏览次数:20433 次

JS解析XML文件和XML字符串

转自http://www.cnblogs.com/chjw8016/archive/2011/07/12/2104269.html

JS解析XML文件

?

复制代码
<script?type='text/javascript'>
????loadXML?
=?function(xmlFile){
????????
var?xmlDoc=null;
????????
//判断浏览器的类型
????????//支持IE浏览器
????????if(!window.DOMParser?&&?window.ActiveXObject){
????????????
var?xmlDomVersions?=?['MSXML.2.DOMDocument.6.0','MSXML.2.DOMDocument.3.0','Microsoft.XMLDOM'];
????????????
for(var?i=0;i<xmlDomVersions.length;i++){
????????????????
try{
????????????????????xmlDoc?
=?new?ActiveXObject(xmlDomVersions[i]);
????????????????????
break;
????????????????}
catch(e){
????????????????}
????????????}
????????}
????????
//支持Mozilla浏览器
????????else?if(document.implementation?&&?document.implementation.createDocument){