案例:XML案例     状态:不可编辑再运行    进入竖版
 运行结果 
x
 
1
<html>
2
<head>
3
4
<script type="text/javascript">
5
if (window.XMLHttpRequest)
6
  {// code for IE7+, Firefox, Chrome, Opera, Safari
7
  xmlhttp=new XMLHttpRequest();
8
  }
9
else
10
  {// code for IE6, IE5
11
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
12
  }
13
xmlhttp.open("GET","/example/xmle/cd_catalog.xml",false);
14
xmlhttp.send();
15
xmlDoc=xmlhttp.responseXML; 
16
17
x=xmlDoc.getElementsByTagName("CD");
18
i=0;
19
20
function displayCD()
21
{
22
artist=(x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue);
23
title=(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);
24
year=(x[i].getElementsByTagName("YEAR")[0].childNodes[0].nodeValue);
25
txt="Artist: " + artist + "<br />Title: " + title + "<br />Year: "+ year;
26
document.getElementById("showCD").innerHTML=txt;
27
}
28
29
function next()
30
{
31
if (i<x.length-1)
32
  {
33
  i++;
34
  displayCD();
35
  }
36
}
37
38
function previous()
39
{
40
if (i>0)
41
  {
42
  i--;
43
  displayCD();
44
  }
45
}
46
</script>
47
</head>
48
<body onload="displayCD()">