Convert DOM to HTML via JavaScript?
<p>Okay so I already know I can get the entire HTML document's markup (minus the DOCTYPE) using:</p>

<pre><code>document.documentElement.outerHTML
</code></pre>

<p>however that will only get me the original source markup, and not the current state of the DOM, which is really what I am looking for. For my immediate needs I really just want to preserve the state of a form within the document (think of it in terms of an an auto-save).</p>

<ul>
<li>Please note this is not being used in a standard website/webapp format, so posting, submitting, etc. really isn't an option. I need a pure JavaScript way to acquire an HTML string representation of the current DOM tree, so an external caller can save it to disk for later use.</li>
</ul>

<p>Now I know I can manually iterate through all the form elements, grabbing each and every value, and doing a string replacement on the result of the above outerHTML (via regular expressions), to build an HTML string that mirrors the current DOM, but I was hoping there was an easier way to do this (maybe something built in). Like a DOM to HTML parser/writer.</p>

<p>However so far I have not found a built in way to do this. Just wanted to reach out and see if anyone else has needed to do this. And ask if my above proposed method the best way to approach this particular problem, before I begin implementing it.</p>