Accessing Tags Inside CDATA


#1

I am able to access the CDATA in NerdFeed application using the following:

[quote]-(void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock
{

NSString *someString = [[NSString alloc] initWithData:CDATABlock encoding:NSUTF8StringEncoding];
[currentString appendFormat:someString];
NSLog(@"CDATA Block %@", (NSString*)someString );

}[/quote]

I am able to see the NSLog messages that shows expanded CDATA.

What i am trying to do is to access different attributes inside CDATA. More specifically i want to access the image url inside CDATA and want to show as thumbnail image in the TableView custom cell.

Can anyone help me how can i do that.

Thanks!


#2

After searching and trying different things i am able to find a solution on StackOverFlow that actually worked. All you need to do is to call “getFirstImageUrl” method from CDATA parser method. The getFirstImageUrl written by someone use NSScanner class to pull the image from CData.

[quote]-(NSString *)getFirstImageUrl: (NSString *) html {
NSScanner *theScanner;
NSString *imageURL = nil;

theScanner = [NSScanner scannerWithString: html];

// find start of tag
[theScanner scanUpToString: @"<img" intoString: NULL];
if ([theScanner isAtEnd] == NO) {

    [theScanner scanUpToString: @"src=\"" intoString: NULL];
    NSInteger newLoc2 = [theScanner scanLocation] + 5;
    [theScanner setScanLocation: newLoc2];

    // find end of tag
    [theScanner scanUpToString: @"\"" intoString: &imageURL];
}

return imageURL;

}[/quote]

Replying my own post just so anyone reaches similar problem.

Thanks