案例: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
x=xmlDoc.getElementsByTagName("title");
12
13
for (i=0;i<x.length;i++)
14
{
15
newatt=xmlDoc.createAttribute("edition");
16
newatt.value="first";
17
x[i].setAttributeNode(newatt);
18
}
19
20
//Output all "edition" attribute values
21
for (i=0;i<x.length;i++)
22
{
23
document.write(x[i].childNodes[0].nodeValue);
24
document.write(" - Edition: ");
25
document.write(x[i].getAttribute("edition"));
26
document.write("<br />");
27
}
28
</script>
29
</body>
30
</html>
31