日期:2014-05-16 浏览次数:20348 次
function loadXML(xmlFile) { var xmlDoc; if (window.ActiveXObject) { xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async = false; xmlDoc.load(xmlFile); } else if (document.implementation && document.implementation.createDocument) { xmlDoc = document.implementation.createDocument("", "", null); xmlDoc.async = false; xmlDoc.load(xmlFile); } else { alert('您的浏览器不支持该系统脚本!'); } return xmlDoc; } function init_list(){ var xmlDoc = loadXML("list.xml"); if(!xmlDoc){ alert("load xml false!"); return false; } if(-1 != xmlDoc.parseError){ //这个地方会显示有错,提示系统未找到指定对象 var oError=xmlDoc.parseError; alert("error code:"+oError.errorCode+"Line:"+oError.line+"Line Pos:"+oError.linepos+"Reason:"+oError.reason); } var all = xmlDoc.getElementsByTagName("songs"); var maxRes = all.length; alert("maxRes="+maxRes);//这个地方显示的长度一直是0 }
<?xml version="1.0" encoding="gb2312"?> <list> <songs> <name>布拉格广场</name> </songs> </list>
xmlDoc.load(xmlFile);