title: python CDATA in subelement
body: <p>I'm trying to add CDATA to an subElement of XML. But the XML keeps converting the <code>&lt;</code> character to <code>&amp;lt;</code>. </p>
  
  <p>I've read <a href="https://stackoverflow.com/questions/174890/how-to-output-cdata-using-elementtree">some posts</a> here that do something with CDATA, but I can't believe it's this hard to make it work. Besides that, I can't get those examples working.</p>
  
  <p>Below a part of my code simplified, using python 3.4.</p>
  
  <p>import xml.etree.cElementTree as ET
  from xml.dom import minidom</p>
  
  <pre><code>class MyClass():
      def __init__(self):
          self.xml = None
  
      def generateXML(self):
          self.xml = ET.Element("AVXML")
          row = ET.SubElement(self.xml, "ROW")
          ET.SubElement(row, "DATA").text = "&lt;![CDATA[ &lt;ART_HDR.COMMENT1&gt;.PDF ]]&gt;"
  
      def saveXML(self):
          rough_string = ET.tostring(self.xml, 'Windows-1252')
          reparsed = minidom.parseString(rough_string)
          prettyxml = reparsed.toprettyxml(indent="  ", encoding="Windows-1252")
  
          print(prettyxml)
  
          f = open("filetosave.xml", "wb")
          f.write(prettyxml)
          f.close()
  
  m = MyClass()
  m.generateXML()
  m.saveXML()
  </code></pre>
  
  <p>This however generates:</p>
  
  <pre><code>&lt;DATA&gt;&amp;lt;![CDATA[ &amp;lt;ART_HDR.COMMENT1&amp;gt;.PDF ]]&amp;gt;&lt;/DATA&gt;
  </code></pre>
  
  <p>Instead of</p>
  
  <pre><code>&lt;DATA&gt;&lt;![CDATA[ &lt;ART_HDR.COMMENT1&gt;.PDF ]]&gt;&lt;/DATA&gt;
  </code></pre>