title: How do I convert XML to HTML in python?
body: <p>I can't get xml.etree.ElementTree to print or acknowledge the correct XHTML header. It insists on giving a generic XML header, prefixing all tags with "html:", throwing exceptions, or a combination of those.</p>
  
  <p>How do I create a valid XHTML document in the first place?</p>
  
  <p>I've got about 4 megabytes of xml files, and I'm trying to create a valid epub from them. There's various munging that needs to be done, <code>&lt;chapter&gt;</code> tags have no place in xhtml, for instance.</p>
  
  <p>the following code:</p>
  
  <pre class="lang-py prettyprint-override"><code>    import xml.etree.ElementTree as ET
      xhtml = ET.fromstring(                                                                          
      "&lt;?xml version=\"1.0\" xmlns=\"http://www.w3.org/1999/xhtml\" ?&gt;\n&lt;head&gt;&lt;title&gt;&lt;/title&gt;&lt;/head&gt;\n&lt;body&gt;\n&lt;/body&gt;")
  </code></pre>
  
  <p>throws:</p>
  
  <blockquote>
    <p>xml.etree.ElementTree.ParseError: XML declaration not well-formed: line 1, column 31</p>
  </blockquote>
  
  <p>If I instead give the "correct" xhtml header, it insists it's html, gives it's own xml header, and prefixes all tags with "html:"</p>
  
  <p>If I give the "correct" xml header, then epubcheck complains about "" not being a valid namespace (which I suppose it isn't).</p>
  
  <p>The theory is that if I could create (and subsequently write out) a valid xhtml document, I could parse my xml for the <code>&lt;body&gt;</code> and <code>&lt;title&gt;</code> that's needed, mung them appropriately (href and src's all need changed, for instance), stick them in there, and be golden.</p>
  
  <p>According to what I've found, a valid xhtml document MUST start with <code>&lt;xhtml xmlns="http://www.w3.org/1999/xhtml&gt;</code> and contain a head (with required title element) and a body. I'm not certain what (if any) of that I can leave out and still pass epubcheck's requirements.</p>
  
  <p>Surely there's a way to force ET to use the correct header? Or do I need to use a different library, or what?</p>