注:判斷是否是ie瀏覽器和非ie瀏覽器的方法有多種,在此只介紹用例中的方法:
1、解析xml字符串,得到xml對象的方式:
function?createXml(str){if(document.all){//IE瀏覽器var?xmlDoc?=?new?ActiveXObject("Microsoft.XMLDOM");xmlDoc.async?=?false;xmlDoc.loadXML(str);return?xmlDoc;}else{//非IE瀏覽器return?new?DOMParser().parseFromString(str,?"text/xml");} }
2、解析xml文件,將其轉換為xml對象的方式:
/** *?aXMLFileName是xml文件路徑名 */ function?getXmlDoc(){try{if?(window.ActiveXObject){xmlDoc=?new?ActiveXObject("Microsoft.XMLDOM");xmlDoc.async?=?false;isLoaded?=?xmlDoc.load(aXMLFileName);}else?if(document.implementation&&?document.implementation.createDocument){try{xmlDoc?=?document.implementation.createDocument('',?'',?null);xmlDoc.async?=?false;xmlDoc.load(aXMLFileName);}?catch(e){var?xmlhttp?=?new?window.XMLHttpRequest();xmlhttp.open("GET",aXMLFileName,false);?xmlhttp.send(null);xmlDoc?=?xmlhttp.responseXML;}}else{alert("load?data?error");}}catch(e){??alert(e.message);} }
JAVA解析xml字符串?
本文出自 “豬會飛” 博客,請務必保留此出處http://jiyanle.blog.51cto.com/6932197/1529727
?