复制一个节点,并把它追加到已有的节点

  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. x=xmlDoc.getElementsByTagName('book')[0];
  11. cloneNode=x.cloneNode(true);
  12. xmlDoc.documentElement.appendChild(cloneNode);
  13.  
  14. //Output all titles
  15. y=xmlDoc.getElementsByTagName("title");
  16. for (i=0;i<y.length;i++)
  17. {
  18. document.write(y[i].childNodes[0].nodeValue);
  19. document.write("<br />");
  20. }
  21. </script>
  22. </body>
  23. </html>