Preserve DOCTYPE of an lxml.etree parsed xml with namespace
<p>This question is almost the same as <a href="https://stackoverflow.com/questions/12966488/preserving-original-doctype-and-declaration-of-an-lxml-etree-parsed-xml">Preserving original doctype and declaration of an lxml.etree parsed xml</a></p>

<p>I want to preserve DOCTYPE declaration with namespace, but the same way of answers of the question above does not preserve declaration.</p>

<pre><code> from lxml import etree
 from StringIO import StringIO

 xml_string = """&lt;?xml version="1.0"?&gt;                                                                
 &lt;!DOCTYPE rdf:RDF [                                                                                  
     &lt;!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" &gt;                                               
     &lt;!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" &gt;                                     
 ]&gt;                                                                                                   
 &lt;rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"&gt;                                    
   &lt;a&gt;&amp;xsd;&lt;/a&gt;                                                                                       
 &lt;/rdf:RDF&gt;                                                                                           
 """

 parse_tree = etree.parse(StringIO(xml_string))
 encoding = parse_tree.docinfo.encoding
 result = etree.tostring(parse_tree, xml_declaration=True, encoding=encoding)
 print "%s\nparse ElementTree:\n%s\n" % ('-'*20, result)
</code></pre>

<p>and the output is:</p>

<pre><code> --------------------
 parse ElementTree:
 &lt;?xml version='1.0' encoding='UTF-8'?&gt;
 &lt;rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"&gt;
   &lt;a&gt;http://www.w3.org/2001/XMLSchema#&lt;/a&gt;                                                           
 &lt;/rdf:RDF&gt;
</code></pre>

<p>Is there still any other way to preserve doctype declaration of original xml tree?</p>