title: How to Load XML File Contents using Javascript?
body: <p>I'm looking for a way to load an XML file's contents directly into a Javascript variable. Say I have the following directory structure:</p>
  
  <pre><code>/index.html
  /loader.js
  /file.xml
  </code></pre>
  
  <p>In <code>index.html</code>, there is a <code>&lt;body&gt;</code> tag, whose contents should be replaced with the contents of the XML file. So if the XML file contains:</p>
  
  <pre><code>&lt;element&gt;
      &lt;item&gt;Item One&lt;/item&gt;
      &lt;item&gt;Item Two&lt;/item&gt;
  &lt;/element&gt;
  </code></pre>
  
  <p>Then after the dynamic load, the HTML would be:</p>
  
  <pre><code>...
  &lt;body&gt;
  &lt;element&gt;
  ...
  &lt;/element&gt;
  &lt;/body&gt;
  ...
  </code></pre>
  
  <p>My question is, what function can I use in <code>loader.js</code> to load the contents straight into a variable? I have used XmlHttpRequests and the ActiveX XMLDOM parser, but all just give me a structural data model that I then have to sort through to find my elements. I don't need to parse anything, I just want to obtain all the file contents.</p>
  
  <p><strong>Note:</strong> HTML/Javascript only, no server-side code.</p>