看过很多资料,做过很多测试,ie上实现读取xml很容易,firefox就麻烦了,这是个什么原因?
var xmlDoc;
//code for IE
if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
//or else if(window.XMLHttpRequest)
{
xmlDoc=document.implementation.createDocument("","",null);
}
xmlDoc.async=false;
xmlDoc.load("productClass.xml");
上面是读取xml代码
有一点:IE里可以把load()方法改成loadXML(),Firefox只能用load()
看看结果:
alert(xmlDoc);
IE:给我们老老实实的弹出个[object]Firefox: 来个[object XMLDocument]
显然,获取到的类型不同
再来
alert(xmlDoc.xml);
IE:弹出了xml文件所有信息Firefox:undefined
所以所谓的xmlDoc.loadXML(xmlDoc.xml.replace(/</g,"<").replace(/>/g,">"));不能用了
已经获取了对象了,只是对象类型不同,现在就是如果处理这个对象,怎么从这个对象取数据
IE下一般使用selectNodes 、selectSingleNode
有待探讨。。。

