title: Displaying XML Attributes in HTML Page
body: <p>I am working on showing details of XML attributes in an HTML page using JavaScript. 
  My XML file is:</p>
  
  <pre><code>&lt;CATALOG&gt;
      &lt;CD&gt;
          &lt;TITLE&gt;Empire Burlesque&lt;/TITLE&gt;
          &lt;ARTIST&gt;Bob Dylan&lt;/ARTIST&gt;
          &lt;COUNTRY&gt;USA&lt;/COUNTRY&gt;
          &lt;COMPANY&gt;Columbia&lt;/COMPANY&gt;
          &lt;PRICE&gt;10.90&lt;/PRICE&gt;
          &lt;YEAR&gt;1985&lt;/YEAR&gt;
      &lt;/CD&gt;
      &lt;CD&gt;
          &lt;TITLE&gt;Hide your heart&lt;/TITLE&gt;
          &lt;ARTIST&gt;Bonnie Tyler&lt;/ARTIST&gt;
          &lt;COUNTRY&gt;UK&lt;/COUNTRY&gt;
          &lt;COMPANY&gt;CBS Records&lt;/COMPANY&gt;
          &lt;PRICE&gt;9.90&lt;/PRICE&gt;
          &lt;YEAR&gt;1988&lt;/YEAR&gt;
      &lt;/CD&gt;
  </code></pre>
  
  <p>Code for the HTML is:</p>
  
  <pre><code>&lt;html&gt;
      &lt;body&gt;
      &lt;script type="text/javascript"&gt;
      if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp=new XMLHttpRequest();
      }
      else
      {// code for IE6, IE5
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      xmlhttp.open("GET","cd_catalog.xml",true);
      xmlhttp.send();
      xmlDoc=xmlhttp.responseXML; 
  
      document.write("&lt;table border='1'&gt;");
      var x=xmlDoc.getElementsByTagName("CD");
      for (i=0;i&lt;x.length;i++)
      { 
          document.write("&lt;tr&gt;&lt;td&gt;");
          document.write(x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue);
          document.write("&lt;/td&gt;&lt;td&gt;");
          document.write(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);
          document.write("&lt;/td&gt;&lt;/tr&gt;");
      }
      document.write("&lt;/table&gt;");
      &lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The problem is that nothing is shown in the browser. Is there any problem in the code above? </p>