通过使用 length 属性来循环节点

  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. for (i=0;i<x.length;i++)
  13. {
  14. document.write(x[i].childNodes[0].nodeValue);
  15. document.write("<br />");
  16. }
  17. </script>
  18. </body>
  19. </html>