IE XML 解析器

 /**
 * XmlParser
 */
var XmlParser = 
{
	LoadXml : function(strXml)
	{
		var xmlDoc;  
		try{  
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");  
			if(!xmlDoc) 
				xmlDoc = new ActiveXObject("MSXML2.DOMDocument.3.0");  
		}
		catch(e){alert("error");}  
		if(!xmlDoc)return null; 
		
		xmlDoc.async = false;  
		var nRet = xmlDoc.loadXML(strXml); 
		
		return nRet ? xmlDoc : null;
	},
	ReadXml : function(xmlDoc, szNodePath, szNodeName)
	{
		var xmlNode = xmlDoc.selectSingleNode(szNodePath);
		if(xmlnode == null)	return null;
		return xmlnode.getAttribute(szNodeName);
	}
}

 一个适用于ie内核的xml解析器。用法:

var xmlstr = '<?xml version="1.0" encodeing="utf-8" ?><xml><key value="Hello World"/></xml>'  
 
var xmldoc = XmlParser.LoadXml(xmlstr);  
var value   = XmlParser.ReadXml(xmldoc, "key", "value");  
  
alert(value); 
 

你可能感兴趣的:(xml,IE,Microsoft)