XMl数据格式如下:
<?xml version="1.0" encoding="gb2312"?>
<root>
<item>
<name>刘亦菲</name>
<url>MingXing/LiuYiFei.htm</url>
<color>7A9D4B</color>
</item>
<item>
<name>蔡依林</name>
<url>MingXing/CaiYiLin.htm</url>
<color>FD0000</color>
</item>
<item>
<name>张娜拉</name>
<url>MingXing/ZhangNaLa.htm</url>
<color>7A9D4B</color>
</item>
<item>
<name>张韶涵</name>
<url>MingXiang/ZhangShaoHan.htm</url>
<color>0000FF</color>
</item>
<item>
<name>张靓颖</name>
<url>MingXing/ZhangLiangYin.htm</url>
<color>7A9D4B</color>
</item>
<item>
<name>李宇春</name>
<url>MingXing/LiYuChun.htm</url>
<color>7A9D4B</color>
</item>
<item>
<name>徐若瑄</name>
<url>MingXing/XuLuXuan.htm</url>
<color>FD0000</color>
</item>
</root>
前端JS脚本代码如下:
//获取网站热门点击排行
var cdsales=new ActiveXObject("Microsoft.XMLDOM"); //创建XmlDom对象
cdsales.async=true; //使用异步加载
cdsales.onreadystatechange=LoadedSales;
function LoadedSales()
{
var txt="";
if(cdsales.readyState==4)
{
if(cdsales.parseError.errorCode != 0)
{
txt="";
}else{
var bi=cdsales.documentElement.selectNodes("item");
if(bi!=null&&bi.length>0)
{
for(var i=0;i<bi.length;i++)
{
txt+="<li>·<a href="+bi[i].childNodes[1].text+" style=color:"+bi[i].childNodes[2].text+">"+bi[i].childNodes[0].text+"</a></li>";
}
}else{
txt="";
}
}
}else{
txt="";
}
sales.innerHTML=txt;
}
function LoadSalesDoc()
{
var Url="/XML/Hot.xml";
cdsales.load(Url);
}