(This is me again)
I am sorry if this is rather vague, but I believe I can give sample code. I am trying to make it that the program pauses parsing after 10 articles are parsed, displays those 10, then continues parsing and displaying another 10 if a next button is pressed.
In the parser.m, i have written:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
currentElement = [elementName copy];
if ([elementName isEqualToString:@"item"]) {
item = [[NSMutableDictionary alloc] init];
self.currentTitle = [[NSMutableString alloc] init];
self.currentDate = [[NSMutableString alloc] init];
self.currentSummary = [[NSMutableString alloc] init];
self.currentLink = [[NSMutableString alloc] init];
self.currentImage = [[NSMutableString alloc] init];
}//IF END
//podcast url is an attribute of the element enclosure
if ([currentElement isEqualToString:@"enclosure"]) {
[currentImage appendString:[attributeDict objectForKey:@"url"]];
NSLog(@"Image = %@", currentImage);
}//IF END
else if([currentElement isEqualToString:@"img"]){
[currentImage appendString:[attributeDict objectForKey:@"src"]];
NSLog(@"Image = %@", currentImage);
}//ELSE IF END
}
I also have the didEndElement and Found characters section:
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"item"]) {
[item setObject:self.currentTitle forKey:@"title"];
[item setObject:self.currentLink forKey:@"link"];
[item setObject:self.currentSummary forKey:@"summary"];
[item setObject:self.currentImage forKey:@"image"];
// Parse date here
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[dateFormatter setDateFormat:@"EEE, d MMM yyyy"]; // Thu, 18 Jun 2010 04:48:09 -0700
NSLog(@"FC date1 = %@", self.currentDate);
NSDate *date = [[NSDate alloc] init];
date = [dateFormatter dateFromString:currentDate];
NSLog(@"FC date2 = %@", date);
[item setObject:self.currentDate forKey:@"date"];
//[item setObject:date forKey:@"date"];
[date release];
[items addObject:[item copy]];
NSLog(@"Item details = %@", items);
[count addObject:[item objectForKey:@"title"]];
NSLog(@"count = %@", count);
}//IF END
}
I have also been having some issues with formatting the date, but thats a minor issue.
also:
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
if ([currentElement isEqualToString:@"title"]) {
[self.currentTitle appendString:string];
} else if ([currentElement isEqualToString:@"link"]) {
[self.currentLink appendString:string];
} else if ([currentElement isEqualToString:@"image"]) {
[self.currentImage appendString:string];
} else if ([currentElement isEqualToString:@"description"]) {
[self.currentSummary appendString:string];
} else if ([currentElement isEqualToString:@"pubDate"]) {
[self.currentDate appendString:string];
NSCharacterSet* charsToTrim = [NSCharacterSet characterSetWithCharactersInString:@" \n"];
[self.currentDate setString: [self.currentDate stringByTrimmingCharactersInSet: charsToTrim]];
}//IF-ELSE-IF END
}
I would be most grateful if someone could give me a tip on what to do to pause the program...or allow me to parse in groups of 10...I am at a loss ;_;
Thank you for your time.