案例:XML DOM案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<html>
2
<head>
3
<script type="text/javascript" src="/example/xdom/loadxmldoc.js"> 
4
</script>
5
</head>
6
<body>
7
8
<script type="text/javascript">
9
xmlDoc=loadXMLDoc("/example/xdom/books.xml");
10
11
var x=xmlDoc.getElementsByTagName('book');
12
13
for(i=0;i<x.length;i++)
14
  {
15
  x.item(i).setAttribute("edition","FIRST");
16
  }
17
18
//Output book title and edition value
19
var x=xmlDoc.getElementsByTagName("title");
20
for (i=0;i<x.length;i++)
21
  {
22
  document.write(x[i].childNodes[0].nodeValue);
23
  document.write(" - Edition: ");
24
  document.write(x[i].parentNode.getAttribute('edition'));
25
  document.write("<br />");
26
  }
27
</script>
28
</body>
29
</html>
30