title: Using JavaScript to parse an XML file
body: <p>I am new to Stack OverFlow and coding in general. I am trying to take an XML file and render it in the browser using JavaScript. I have looked around at some sample code of how to do this and came up with the following code:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;body&gt;
  
  &lt;script&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","social.xml",false);
    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("c_id")[0].childNodes[0].nodeValue);
    document.write("&lt;/td&gt;&lt;td&gt;");
    document.write(x[i].getElementsByTagName("facebook_id")[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>Anyway, when I run this on my local server none of the data that I am trying to display in the table appears. My .html file and .xml file are in the same folder, so I believe I have the correct file pathway. I could just be making a rookie mistake here, but I can't for the life of me figure out why a table listing the c_id and facebook_id values is not being created. I looked around for answers and haven't been able to find any. Any help would be greatly appreciated. Thanks!</p>