Note that there are some explanatory texts on larger screens.

plurals
  1. POUse NSXMLParser to only parse the first ten posts, then parse next lot separately
    text
    copied!<p>I am using NSXmlParser to parse through an rss feed. All is working well so far. </p> <p>I'm anticipating the rss feed will eventually contains dozens/hundreds of posts. My current solution is reading the entire rss feed and displaying the results. However I want to only read the first ten posts (to prevent it parsing potentially hundreds of items). Then at a later time (say when the user reaches the end of the table) to parse the next ten posts. </p> <p>So my question is how would I parse the first ten posts, then parse the next ten posts, then the next ten posts and so on...</p> <p>Here is what I am using to get ALL posts:</p> <pre><code>- (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]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload