title: In JavaScript, how can serializer part of the DOM to XHTML?
body: <p>I would like to serialize part of the DOM to XHTML (valid XML). Let's assume I have just one element inside <code>&lt;body&gt;</code>, and that this is the element I want to serialize:</p>
  
  <pre><code>&lt;div&gt;
      &lt;hr&gt;
      &lt;img src="/foo.png"&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>With this, <code>document.innerHTML</code> gives me almost what I want, except it returns HTML, not XHTML (i.e. the <code>&lt;hr&gt;</code> and <code>&lt;img&gt;</code> won't be properly closed). Since <code>innerHTML</code> doesn't do the trick, how can I serialize part of the DOM to XHTML?</p>