创建文本节点/创建元素节点

  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. newel=xmlDoc.createElement("edition");
  12. newtext=xmlDoc.createTextNode("first");
  13. newel.appendChild(newtext);
  14.  
  15. x=xmlDoc.getElementsByTagName("book")[0];
  16. x.appendChild(newel);
  17.  
  18. //Output title and edition
  19. document.write(x.getElementsByTagName("title")[0].childNodes[0].nodeValue);
  20. document.write(" - Edition: ");
  21. document.write(x.getElementsByTagName("edition")[0].childNodes[0].nodeValue);
  22. </script>
  23. </body>
  24. </html>