0
我做一個測試,我建立一個新聞提要iOS應用的縮略圖要素,使用RSS提要像這樣的:http://www.20minutos.es/iphoneapp/feeds/home/無法找到RSS提要
我幾乎已經完成,但我找不到縮略圖的鏈接。我做這樣的分析,我可以找到一些外殼,enclosure2x,縮略圖,thumbnail2x,但他們都空字符串:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
element = elementName;
if ([element isEqualToString:@"item"]) {
item = [[NSMutableDictionary alloc] init];
title = [[NSMutableString alloc] init];
link = [[NSMutableString alloc] init];
image = [[NSMutableString alloc] init];
image2x = [[NSMutableString alloc] init];
comments = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:@"item"]) {
[item setObject:title forKey:@"title"];
[item setObject:link forKey:@"link"];
[item setObject:image forKey:@"image"];
[item setObject:image2x forKey:@"image2x"];
[item setObject:comments forKey:@"comments"];
[feeds addObject:[item copy]];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if ([element isEqualToString:@"title"]) {
[title appendString:string];
} else if ([element isEqualToString:@"link"]) {
[link appendString:string];
} else if ([element isEqualToString:@"veinteminutos:numComments"]) {
[comments appendString:[string stringByReplacingOccurrencesOfString:@" " withString:@""]];
}
//NSLog(@"string: %@ \nelement: %@ \n\n\n", string, element);
}
這是我第一次解析RSS提要,所以我真的不知道在那裏尋找什麼。
感謝
這很好,解決了我的問題。謝謝 – kanstraktar