Javascript XML

	function loadXMLDoc(dname) {
		try{ //Internet Explorer
	  		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	  	} catch(e) {
	  		try{ //Firefox, Mozilla, Opera, etc.
	    	xmlDoc=document.implementation.createDocument("","",null);
	    	} catch(e) {alert(e.message)}
	  	}
		try {
	  		xmlDoc.async=false;
	  		xmlDoc.load(dname);
	  		return(xmlDoc);
	  	} catch(e) {alert(e.message)}
	  	
		return(null);
	}
	
	function loadXMLString(txt) {
		try{ //Internet Explorer
			xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  			xmlDoc.async="false";
  			xmlDoc.loadXML(txt);
  			return(xmlDoc); 
  		} catch(e) {
	  		try{ //Firefox, Mozilla, Opera, etc.
	    		parser=new DOMParser();
	    		xmlDoc=parser.parseFromString(txt,"text/xml");
	    		return(xmlDoc);
	    	} catch(e) {alert(e.message)}
  		}
		return(null);
	}
 

你可能感兴趣的:(JavaScript)