Using NSXMLParser with CDATA

Posted by Robb on Stack Overflow See other posts from Stack Overflow or by Robb
Published on 2009-07-08T01:55:58Z Indexed on 2010/04/16 14:03 UTC
Read the original article Hit count: 729

I'm parsing an RSS feed with NSXMLParser and it's working fine for the title and other strings but one of the elements is an image thats like

<!CDATA <a href="http:image..etc>

How do I add that as my cell image in my table view? Would I define that as an image type?

This is what i'm using to do my parsing:

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{    		
//NSLog(@"found this element: %@", elementName);
currentElement = [elementName copy];
if ([elementName isEqualToString:@"item"]) {
	// clear out our story item caches...
	item = [[NSMutableDictionary alloc] init];
	currentTitle = [[NSMutableString alloc] init];
	currentDate = [	[NSMutableString alloc] init];
	currentSummary = [[NSMutableString alloc] init];
	currentLink = [[NSMutableString alloc] init];
}

}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{     
//NSLog(@"ended element: %@", elementName);
if ([elementName isEqualToString:@"item"]) {
	// save values to an item, then store that item into the array...
	[item setObject:currentTitle forKey:@"title"];
	[item setObject:currentLink forKey:@"link"];
	[item setObject:currentSummary forKey:@"description"];
	[item setObject:currentDate forKey:@"date"];

	[stories addObject:[item copy]];
	NSLog(@"adding story: %@", currentTitle);
}

}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
//NSLog(@"found characters: %@", string);
// save the characters for the current item...
if ([currentElement isEqualToString:@"title"]) {
	[currentTitle appendString:string];
} else if ([currentElement isEqualToString:@"link"]) {
	[currentLink appendString:string];
} else if ([currentElement isEqualToString:@"description"]) {
	[currentSummary appendString:string];
} else if ([currentElement isEqualToString:@"pubDate"]) {
	[currentDate appendString:string];
}

}

© Stack Overflow or respective owner

Related posts about nsxmlparser

Related posts about iphone-sdk