案例:XML DOM案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<html>
2
<head>
3
<script type="text/javascript" src="/example/xdom/loadxmldoc.js"> 
4
</script>
5
</head>
6
<body>
7
<script type="text/javascript">
8
//check if the first node is an element node
9
function get_firstchild(n)
10
{
11
var x=n.firstChild;
12
while (x.nodeType!=1)
13
  {
14
  x=x.nextSibling;
15
  }
16
return x;
17
}
18
19
xmlDoc=loadXMLDoc("/example/xdom/books.xml");
20
21
var x=xmlDoc.documentElement;
22
var firstNode=get_firstchild(x);
23
24
for (var i=0;i<firstNode.childNodes.length;i++)
25
{ 
26
if (firstNode.childNodes[i].nodeType==1)
27
  { 
28
  //Process only element nodes
29
  document.write(firstNode.childNodes[i].nodeName);
30
  document.write(" = ");
31
  document.write(firstNode.childNodes[i].childNodes[0].nodeValue);
32
  document.write("<br />");
33
  } 
34
}
35
36
</script>
37
</body>
38
</html>
39