案例:XML DOM案例     状态:可编辑再运行    进入横版
x
 
1
<html>
2
3
<head>
4
<script type="text/javascript" src="/example/xdom/loadxmldoc.js"> 
5
</script>
6
</head>
7
8
<body>
9
<script type="text/javascript">
10
//检查最后一个节点是否是元素节点
11
function get_lastchild(n)
12
{
13
var x=n.lastChild;
14
while (x.nodeType!=1)
15
  {
16
  x=x.previousSibling;
17
  }
18
return x;
19
}
20
21
xmlDoc=loadXMLDoc("/example/xdom/books.xml");
22
23
document.write("book 节点的数目:");
24
document.write(xmlDoc.getElementsByTagName('book').length);

 运行结果 
 北美留学生论坛