Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for CDATA elements. #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions KissXML/DDXMLElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- (id)initWithName:(NSString *)name;
- (id)initWithName:(NSString *)name URI:(NSString *)URI;
- (id)initWithName:(NSString *)name stringValue:(NSString *)string;
- (id)initWithName:(NSString *)name cdata:(NSString *)cdata;
- (id)initWithXMLString:(NSString *)string error:(NSError **)error;

#pragma mark --- Elements by name ---
Expand Down
17 changes: 17 additions & 0 deletions KissXML/DDXMLElement.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,23 @@ - (id)initWithName:(NSString *)name stringValue:(NSString *)string
return result;
}

- (id)initWithName:(NSString *)name cdata:(NSString *)cdata
{
xmlNodePtr node = xmlNewNode(NULL, [name xmlChar]);
if (node == NULL)
{
return nil;
}

const char * content = cdata.UTF8String;
xmlNodePtr cdataNode = xmlNewCDataBlock(node->doc, BAD_CAST content, (int)strlen(content));
xmlAddChild(node, cdataNode);

DDXMLElement *result = [self initWithElementPrimitive:node owner:nil];

return result;
}

- (id)initWithXMLString:(NSString *)string error:(NSError **)error
{
DDXMLDocument *doc = [[DDXMLDocument alloc] initWithXMLString:string options:0 error:error];
Expand Down
2 changes: 2 additions & 0 deletions KissXML/DDXMLNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ enum {

+ (id)elementWithName:(NSString *)name stringValue:(NSString *)string;

+ (id)elementWithName:(NSString *)name cdata:(NSString *)cdata;

+ (id)elementWithName:(NSString *)name children:(NSArray *)children attributes:(NSArray *)attributes;

+ (id)attributeWithName:(NSString *)name stringValue:(NSString *)stringValue;
Expand Down
5 changes: 5 additions & 0 deletions KissXML/DDXMLNode.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ + (id)elementWithName:(NSString *)name stringValue:(NSString *)string
return [[DDXMLElement alloc] initWithName:name stringValue:string];
}

+ (id)elementWithName:(NSString *)name cdata:(NSString *)cdata
{
return [[DDXMLElement alloc] initWithName:name cdata:cdata];
}

+ (id)elementWithName:(NSString *)name children:(NSArray *)children attributes:(NSArray *)attributes
{
DDXMLElement *result = [[DDXMLElement alloc] initWithName:name];
Expand Down