Even though the solution by @moq is ugly, it works. I have cleaned up the string creation code and added it into a category.
DDXMLNode+CDATA.h:
#import <Foundation/Foundation.h>
#import "DDXMLNode.h"
@interface DDXMLNode (CDATA)
/**
Creates a new XML element with an inner CDATA block
<name><![CDATA[string]]></name>
*/
+ (id)cdataElementWithName:(NSString *)name stringValue:(NSString *)string;
@end
DDXMLNode+CDATA.m:
#import "DDXMLNode+CDATA.h"
#import "DDXMLElement.h"
#import "DDXMLDocument.h"
@implementation DDXMLNode (CDATA)
+ (id)cdataElementWithName:(NSString *)name stringValue:(NSString *)string
{
NSString* nodeString = [NSString stringWithFormat:@"<%@><![CDATA[%@]]></%@>", name, string, name];
DDXMLElement* cdataNode = [[DDXMLDocument alloc] initWithXMLString:nodeString
options:DDXMLDocumentXMLKind
error:nil].rootElement;
return [cdataNode copy];
}
@end
The code is also available in this gist.