Hot.xml文件 :
刘亦菲
MingXing/LiuYiFei.htm
red
蔡依林
MingXing/CaiYiLin.htm
blue
张娜拉
MingXing/ZhangNaLa.htm
green
张韶涵
MingXiang/ZhangShaoHan.htm
grey
张靓颖
MingXing/ZhangLiangYin.htm
black
李宇春
MingXing/LiYuChun.htm
yellow
徐若瑄
MingXing/XuLuXuan.htm
pink
demo1.html文件:
JavaScript获取XML数据var xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); //创建XmlDom对象
xmlDoc.async=true; //使用异步加载
xmlDoc.onreadystatechange=loadedSales;
function loadedSales()
{
var txt="";
if(xmlDoc.readyState == 0){
alert("0");
}
if(xmlDoc.readyState == 1){
alert("1");
}
if(xmlDoc.readyState == 2){
alert("2");
}
if(xmlDoc.readyState == 3){
alert("3");
}
if(xmlDoc.readyState == 4)
{
if(xmlDoc.parseError.errorCode != 0)
{
txt="xml解析错误!";
}else{
var items=xmlDoc.documentElement.selectNodes("item");
if(items != null && items.length > 0)
{
for(var i=0; i < items.length; i++)
{
txt += "
"+items[i].childNodes[0].text+"";}
}else{
txt="";
}
}
}else{
txt="";
}
document.getElementById("sales").innerHTML=txt;
}
function loadXmlDoc()
{
var url="Hot.xml";
xmlDoc.load(url);
}
效果图: