title: Can I load an entire HTML document into a document fragment in Internet Explorer?
body: <p>Here's something I've been having a little bit of difficulty with. I have a local client-side script that needs to allow a user to fetch a remote web page and search that resulting page for forms. In order to do this (without regex), I need to parse the document into a fully traversable DOM object.</p>
  <p>Some limitations I'd like to stress:</p>
  <ul>
  <li>I don't want to use libraries (like jQuery). There's too much bloat for what I need to do here.</li>
  <li>Under no circumstances should scripts from the remote page be executed (for security reasons).</li>
  <li>DOM APIs, such as <code>getElementsByTagName</code>, need to be available.</li>
  <li>It only needs to work in Internet Explorer, but in 7 at the very least.</li>
  <li>Let's pretend I don't have access to a server. I do, but I can't use it for this.</li>
  </ul>
  <h2>What I've tried</h2>
  <p>Assuming I have a complete HTML document string (including DOCTYPE declaration) in the variable <code>html</code>, here's what I've tried so far:</p>
  <pre><code>var frag = document.createDocumentFragment(),
  div  = frag.appendChild(document.createElement(&quot;div&quot;));
  
  div.outerHTML = html;
  //-&gt; results in an empty fragment
  
  div.insertAdjacentHTML(&quot;afterEnd&quot;, html);
  //-&gt; HTML is not added to the fragment
  
  div.innerHTML = html;
  //-&gt; Error (expected, but I tried it anyway)
  
  var doc = new ActiveXObject(&quot;htmlfile&quot;);
  doc.write(html);
  doc.close();
  //-&gt; JavaScript executes
  </code></pre>
  <p>I've also tried extracting the <code>&lt;head&gt;</code> and <code>&lt;body&gt;</code>nodes from the HTML and adding them to a <code>&lt;HTML&gt;</code> element inside the fragment, still no luck.</p>
  <p>Does anyone have any ideas?</p>