Skip to content

Instantly share code, notes, and snippets.

@imrekel
Created November 21, 2012 13:31
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save imrekel/4124847 to your computer and use it in GitHub Desktop.
Save imrekel/4124847 to your computer and use it in GitHub Desktop.
CDATA node support for KissXML
#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
#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment