使用 length 属性来循环节点

  1. <html>
  2. <head>
  3. <script type="text/javascript" src="/example/xdom/loadxmldoc.js"></script>
  4. </head>
  5. <body>
  6.  
  7. <script type="text/javascript">
  8. xmlDoc=loadXMLDoc("/example/xdom/books.xml");
  9.  
  10. x=xmlDoc.getElementsByTagName("title");
  11. for (i=0;i<x.length;i++)
  12. {
  13. document.write(x[i].childNodes[0].nodeValue);
  14. document.write("<br />");
  15. }
  16. </script>
  17. </body>
  18. </html>