添加一个新属性/ 通过使用 setAttribute 来创建属性节点

  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. x[0].setAttribute("edition","first");
  14.  
  15. document.write("Edition: ");
  16. document.write(x[0].getAttribute("edition"));
  17.  
  18. </script>
  19. </body>
  20. </html>