CDATA means character data. When you write
<![CDATA[ <x>3</x> ]]>
you are telling the system "x might look like an element, but it isn't one, it is ordinary character data". This means that to construct such output, you shouldn't create x as an element, you should construct it as text.
The first thing I would say is, are you really obliged to generate this output - because it is a bad design and a bad misuse of XML.
However, there are tricks you can use if you really have to do it, provided that the XML is being serialized using an XSLT serializer (this means it won't work in Firefox, for example). Basically, generate the start and end CDATA markers using d-o-e
<xsl:text disable-output-escaping="yes"><!CDATA[[</xsl:text>
It's a horrible kludge and it would be much better to redesign the output XML format, but it's there to use if you're desperate.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference