The task is incorrectly formulated IMHO. I consulted with XML pros and here's the situation.
1. XML 1.0 http://www.w3.org/TR/REC-xml/#sec-cdata-sect says: "Within a CDATA section, only the CDEnd string is recognized as markup, so that left angle brackets and ampersands may occur in their literal form; they need not (and cannot) be escaped using "<" and "&". CDATA sections cannot nest."
2. DOM Level 3 Core http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#DOMConfiguration defines DOMConfiguration parameter "cdata-sections" which determines whether CDATA must be converted to text nodes on serialization or not. There's also an entry in DOM FAQ for how this conversion must be done: http://www.w3.org/DOM/faq.html#CDTA-text
Currently Scala converts CDATA nodes to Text nodes (cdata-sections=false). The behaviour I (and David Pollak for 3 years advocate for is to see CDATA sections serialized unchanged (cdata-sections=true), because:
2. One already can define text nodes in XML literals;
3. Generally, Scala should check XML literal wellformedness, but NOT perform any conversions. Same problem is tracked by ticket
SI-1118 (<br/> vs <br></br>). Latest comments there show that guys came to preserving element emptiness mode as specified in XML literal, and that's great.
So I suggest ticket should be renamed to "Preserve CDATA sections".