Use NSXMLParser to parse only the first ten messages, then parse the next lot separately

I am using NSXmlParser for analysis via RSS feed. So far, everything is working.

I expect the rss feed will eventually contain tens / hundreds of messages. My current solution reads the entire rss feed and displays the results. However, I only want to read the first ten posts (to prevent it from parsing potentially hundreds of elements). Then at a later time (say, when the user reaches the end of the table) to analyze the next ten messages.

So my question is how I analyze the first ten messages, then analyze the next ten messages, then the next ten messages, and so on ...

Here is what I use to get ALL messages:

- (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];

}
+5
4

, , , , 10 100 , - . , :

  • , ( XML).
  • 10 ,
  • .

, , "" () "" rss , (. Instagram )

+7

[rssParser abortParsing], . , , xml. - -. NSXMLParser .

0

var :

...
@private
  NSUInteger rssCounter;
...
@property (nonatomic, assign) NSUInteger rssCounter;
...

init:

rssCounter = 0;

, , , @Metalmi, if else .

, 0, 10, , .

- :

- (void)restartParsing:(NSString *)url
{
  rssCounter = 0
  [self parseXMLFileAtURL:url];
}

, .

0

@coneybeare, xml .

, xml " ", , xmlParseChunk libxml (. XMLPerformance). -, , , .

Another way is to take any free Objective-C open source wml analyzer (maybe even a DOM-parser like TBXML ) and break its internal parse pair in a way that suits you.

0
source

All Articles