日期:2014-05-16 浏览次数:20465 次
<?xml version='1.0' encoding='utf-8'?>
<metadata type='LABEL'>
<version>LABEL.1.06.0</version>
<list count="3">
<level width="9708">1</level>
<level width="8708">2</level>
<level width="7708">3</level>
</list>
</metadata>
function LoadXML(url) {
var xhr = window.ActiveXObject ? new ActiveXObject("microsoft.xmlhttp") : new XMLHttpRequest()
,dom;
xhr.open("get", url, false);
xhr.send(null);
if (0 == xhr.status
------其他解决方案--------------------
200 == xhr.status) {
if (document.all && 0 == xhr.status) {//IE浏览器下非http的ajax请求xml文件无法生成XML的DOM对象,需要使用microsoft.xmldom重生生成
dom = new ActiveXObject("microsoft.xmldom");
dom.loadXML(xhr.responseText);
}
else dom = xhr.responseXML;
}
else aler('加载XML失败!' + xhr.responseText);
return dom;
}
var dom = LoadXML("x.xml?_dc=" + new Date().getTime());/////注意修改路径
if (dom) {
var version = dom.getElementsByTagName('version')[0], levelNode = dom.getElementsByTagName('level'), arrWidth = [];
version = version.firstChild.nodeValue;
for (var i = 0; i < levelNode.length; i++) arrWidth[i] = levelNode[i].getAttribute('width');
alert('version:' + version + '\nwidth数组:' + arrWidth)
}