我解析用的NSXMLParser一个RSS feed,它的做工精细的标题和其他字符串,但要素之一是图像多数民众赞成像使用的NSXMLParser与CDATA
<!CDATA <a href="http:image..etc>
如何添加,作为我的我的表格视图中的细胞图像?我会将其定义为图像类型吗?
这是我用来做我的分析是什么:
- (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];
}
}
是的,有这样的图像URL在那里。如何使用NSXMLParser提取图像URL? – Xcoder 2009-07-08 02:37:27
查看CDATA部分内的字符串。如果它始终是有效的xml,则在*那个*字符串上触发另一个NSXMLParser实例。 如果它不是有效的XML,则必须执行Something Else™,例如,手动查找标签。 – Justicle 2009-07-08 03:32:01