Hot.xml문서 :
复代码代码如下:
<?xml version="1.0" 인코딩="gb2312"?>
<루트>
<아이템>
<name>刘亦菲</name>
<url>MingXing/LiuYiFei.htm</url>
<color>빨간색</color>
</item>
<아이템>
<name>蔡依lin</name>
<url>MingXing/CaiYiLin.htm</url>
<color>파란색</color>
</item>
<아이템>
<name>张娜拉</name>
<url>MingXing/ZhangNaLa.htm</url>
<color>녹색</color>
</item>
<아이템>
<name>张韶涵</name>
<url>MingXiang/ZhangShaoHan.htm</url>
<color>회색</color>
</item>
<아이템>
<name>张靓颖</name>
<url>MingXing/ZhangLiangYin.htm</url>
<color>검은색</color>
</item>
<아이템>
<name>이宇春</name>
<url>MingXing/LiYuChun.htm</url>
<color>노란색</color>
</item>
<아이템>
<name>徐若</name>
<url>MingXing/XuLuXuan.htm</url>
<color>분홍색</color>
</item>
</root>
데모1.html문서:
<html xmlns="http://www.w3.org/1999/xhtml">
<머리>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JavaScript의 XML 형식</title>
<스크립트 언어="자바스크립트">
复代码代码如下:
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); //创建XmlDom对象
xmlDoc.async=true; //使用异步加载
xmlDoc.onreadystatechange=loadedSales;
함수loadSales()
{
var txt="";
if(xmlDoc.readyState == 0){
경고("0");
}
if(xmlDoc.readyState == 1){
경고("1");
}
if(xmlDoc.readyState == 2){
경고("2");
}
if(xmlDoc.readyState == 3){
경고("3");
}
if(xmlDoc.readyState == 4)
{
if(xmlDoc.parseError.errorCode != 0)
{
txt="xml解析错误!";
}또 다른{
var items=xmlDoc.documentElement.selectNodes("item");
if(items != null && items.length > 0)
{
for(var i=0; i < items.length; i++)
{
txt += "<li><a href="+items[i].childNodes[1].text+" mce_href="+items[i].childNodes[1].text+" style="color:" mce_style=" 색상:""+items[i].childNodes[2].text+">"+items[i].childNodes[0].text+"</a></li>";
}
}또 다른{
txt="";
}
}
}또 다른{
txt="";
}
document.getElementById("판매").innerHTML=txt;
}
함수 loadXmlDoc()
{
var url="Hot.xml";
xmlDoc.load(url);
}
</script>
</head>
<body onLoad="loadXmlDoc()">
<div id="판매"></div>
</body>
</html>
效果图: