我正在使用NSXmlParser来解析RSS Feed.到目前为止一切运作良好.
我预计RSS Feed最终会包含几十个/几百个帖子.我目前的解决方案是读取整个RSS Feed并显示结果.但是我想只阅读前十个帖子(以防止它解析可能有数百个项目).然后在稍后的时间(例如当用户到达表的末尾时)来解析接下来的十个帖子.
所以我的问题是如何解析前十个帖子,然后解析接下来的十个帖子,然后解析接下来的十个帖子等等……
- (void)parseXMLFileAtURL:(NSString *)URL { myArray = [[NSMutableArray alloc] init]; //convert the path to a proper NSURL or it won't work NSURL *xmlURL = [NSURL URLWithString:URL]; RSSParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL]; [RSSParser setDelegate:self]; [RSSParser parse]; } - (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError { //error } - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ currentElement = [elementName copy]; if ([elementName isEqualToString:@"item"]) { //clear out our story item caches... item = [[NSMutableDictionary alloc] init]; } } - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{ if ([elementName isEqualToString:@"item"]) { // save values to an item,then store that item into the array... } } - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{ // save the characters for the current item... } - (void)parserDidEndDocument:(NSXMLParser *)parser { [myTable reloadData]; }