I've tried this:
GDataXMLElement * body = [GDataXMLNode elementWithName:@"body"];
[body addChild:[GDataXMLNode elementWithName:@"request" stringValue:@"<![CDATA[ <hello> ]]>"]];
NSLog(@"%@",[body XMLString]);
And it outputs:
<body
><request
>&
lt;![CDATA[
<hello
> ]]
>
</request
><
/body`>
But want it to be like this:
<body
><request
><![CDATA[ <hello> ]]><
/request>
</body
>
any idea how can I tell the parser that the GDataXMLNode should be a CDATA kind?
CDATA sections can appear inside element content and allow < and & character literals to appear. A CDATA section begins with the character sequence <! [CDATA[ and ends with the character sequence ]]>. Between the two character sequences, an XML processor ignores all markup characters such as <, >, and &.
CDATA is defined as blocks of text that are not parsed by the parser, but are otherwise recognized as markup. The predefined entities such as <, >, and & require typing and are generally difficult to read in the markup.
A CDATA section is used to mark a section of an XML document, so that the XML parser interprets it only as character data, and not as markup. It comes handy when one XML data need to be embedded within another XML document.
Did you trying using:
[[GDataXMLElement alloc] initWithXMLString:"<![CDATA[ .... ]]>"]
Baseed on the source this parses it directly as XML:
const char *utf8Str = [str UTF8String];
xmlDocPtr doc = xmlReadMemory(utf8Str, (int)strlen(utf8Str), NULL, // URL
NULL, // encoding
kGDataXMLParseOptions);
Whereas elementWithName
just grabs the string verbatim:
+ (GDataXMLElement *)elementWithName:(NSString *)name {
xmlNodePtr theNewNode = xmlNewNode(NULL, // namespace
GDataGetXMLString(name));
if (theNewNode) {
// succeeded
return [self nodeConsumingXMLNode:theNewNode];
}
return nil;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With