1 #!/usr/bin/env python 2 # -*- coding: iso-8859-15 -*- 3 4 import libxml2dom 5 d = libxml2dom.parseString("""<?xml version='1.0' encoding="iso-8859-15"?> 6 <doc> 7 <![CDATA[I am the character data champion! ??????]]> 8 </doc> 9 """) 10 d2 = libxml2dom.createDocument("http://www.w3.org/1999/xhtml", "html", 11 libxml2dom.createDocumentType("html", "-//W3C//DTD XHTML 1.1//EN", "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd")) 12 doc = d.xpath("doc")[0] 13 doc2 = d2.importNode(doc, 1) 14 html = d2.xpath("*")[0] 15 html.appendChild(doc2) 16 17 print d2.toString("iso-8859-15") 18 19 # vim: tabstop=4 expandtab shiftwidth=4