title: XMLHttpRequest Object : can't retrieve data from XML using responseXML
body: <p>I am using XMLHttpRequest to get responseXML from JSP which has XML content.But not able to get node values from the responseXML Object.Even the root node is shown as null.</p>
  
  <p>I am using IE8.
  Below is the code i am using.</p>
  
  <pre><code>function function2(){
  var xhr=new XMLHttpRequest();
  
  xhr.onreadystatechange=function(){
      if(xhr.readyState==4){
          if(xhr.status==200){
          var xhrResponse=xhr.responseXML;    
              alert(xhr.responseText);
              alert(xhrResponse==null);
              alert(xhr.getAllResponseHeaders());
              var theRoot = xhrResponse.documentElement;
              alert(theRoot);
              alert(theRoot.getElementsByTagName("Name")[0].childNodes[0].nodeValue);
  
              alert(xhrResponse.getElementsByTagName("Name").length);     
          }
      }
  }
  
  xhr.open("GET", "jspXML.jsp" ,true);
  xhr.setRequestHeader("Content-Type", "text/xml");   
  xhr.send();
  }   
  </code></pre>
  
  <p>Server Side Scripting:</p>
  
  <pre><code>&lt;%@ page contentType="text/xml" %&gt;
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;%response.setContentType("text/xml"); %&gt;
  &lt;College&gt;
  &lt;Student&gt;
      &lt;Name&gt;A&lt;/Name&gt;
      &lt;Age&gt;10&lt;/Age&gt;
  &lt;/Student&gt;
  &lt;Student&gt;
      &lt;Name&gt;B&lt;/Name&gt;
      &lt;Age&gt;20&lt;/Age&gt;
  &lt;/Student&gt;
  &lt;Student&gt;
      &lt;Name&gt;C&lt;/Name&gt;
      &lt;Age&gt;30&lt;/Age&gt;
  &lt;/Student&gt;
  &lt;/College&gt;
  </code></pre>
  
  <p>From alert messages ,found that responseXML is Not null and it is an {object].But the root element (using documentElement) is null.</p>
  
  <p>But responseText is showing properly.</p>
  
  <p>1.Is this behavior browser-dependent ?</p>
  
  <p>2.When i googled this issue,many solutions suggetsed to set the request header as "text/xml".As per my understanding ,the responseXML is retrieved using response header.So,do i need really need to set request header or setting response header is the correct way?</p>
  
  <p>Can anyone tell whether i am missing something?Thanks.</p>