I am sending a flatpage content as an xml but content carries some CData for scripts. I have to include that CData within my main Cdata. I have to containt all the flatpage content in CDATA,while a script within content includes another CData like;\[code\] <page><![CDATA[<script type="text/javascript">// <![CDATA[ $(document).ready(function(){ $(".fancybox").fancybox(); });// ]]></script>.........\[/code\]But I get an Below is a rendering of the page up to the first error. from the browser XML error. Below is my python code that I make the string replacements within for loop with my raw.xml file under the python code\[code\]def static_page_list(request):if HOSTNAME == "XYZ": filename = "/path/to/raw.xml" targetfile = "/path/to/targetfile"static = StaticPages.objects.all().order_by('title')with open(filename,'r+') as f: with open(targetfile,'w+') as w: w.write('<?xml version="1.0" encoding="utf-8"?> <Documents xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="data_static.xsd">') old = f.read() for i in static: j = i.title j = smart_str(j) s = old.replace('titlesss',j,1) content = i.page decoded = BeautifulStoneSoup(content, convertEntities=BeautifulStoneSoup.HTML_ENTITIES) x = str(decoded) y = unicode(x,'utf-8') y = smart_str(y) s = s.replace('pagesss',y,1) s = s.replace('&','',20) s = smart_str(s) w.write(s) w.write("</Documents>") w.close() f.close()return HttpResponseRedirect("/site_media/xml/static_list_output.xml")\[/code\]RAW XML file\[code\]<class> <title><![CDATA[titlesss]]></title> <page><![CDATA[pagesss]]></page></class>\[/code\]