案例:XML案例     状态:可编辑再运行    进入竖版
 运行结果 
x
<button onclick="loadXMLDoc('/example/xdom/cd_catalog.xml')">Get CD info</button>
 
1
<html>
2
<head>
3
<script type="text/javascript">
4
var xmlhttp;
5
6
function loadXMLDoc(url)
7
{
8
xmlhttp=null;
9
if (window.XMLHttpRequest)
10
  {// code for IE7, Firefox, Mozilla, etc.
11
  xmlhttp=new XMLHttpRequest();
12
  }
13
else if (window.ActiveXObject)
14
  {// code for IE5, IE6
15
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
16
  }
17
if (xmlhttp!=null)
18
  {
19
  xmlhttp.onreadystatechange=onResponse;
20
  xmlhttp.open("GET",url,true);
21
  xmlhttp.send(null);
22
  }
23
else
24
  {
25
  alert("Your browser does not support XMLHTTP.");
26
  }
27
}
28
29
function onResponse()
30
{
31
if(xmlhttp.readyState!=4) return;
32
if(xmlhttp.status!=200)
33
  {
34
  alert("Problem retrieving XML data");
35
  return;
36
  }
37
38
txt="<table border='1'>";
39
x=xmlhttp.responseXML.documentElement.getElementsByTagName("CD");
40
for (i=0;i<x.length;i++)
41
  {
42
  txt=txt + "<tr>";
43
  xx=x[i].getElementsByTagName("TITLE");
44
    {
45
    try
46
      {
47
      txt=txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";
48
      }