6

I have an error while reading XML files for my iPhone app. I have a new feature on my iPhone app that reads my RSS feed. Everything looks good by but I have this issue:

Error while loading rss. Please check your Internet connection

Here's my code:

- (BOOL) readRSS {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    [[NSURLCache sharedURLCache] setMemoryCapacity:0];
    [[NSURLCache sharedURLCache] setDiskCapacity:0];
    BOOL success = NO;
    NSXMLParser *parser = nil;
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://rss.domain.com/%@.xml", self.currentPage]];
    parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
    [parser setDelegate:self];
    [parser setShouldProcessNamespaces:NO];
    [parser setShouldReportNamespacePrefixes:NO];
    [parser setShouldResolveExternalEntities:NO];
    success = [parser parse];
    [parser release];
    [pool drain];
    return success;
}

Then I have this code:

- (void) cleartbl:(NSInteger)type {
    [[[self rssParser] rssItems] removeAllObjects];
    [_tableView reloadData];
    if(type == 1) {
        UIAlertView *alert = [[UIAlertView alloc] 
                          initWithTitle:@"RSS Feed" 
                          message:@"Error while loading rss. Please check your Internet connection."
                          delegate:nil 
                          cancelButtonTitle:@"OK" 
                          otherButtonTitles: nil];
        [alert show];   
        [alert release];
    }

Then i assign:

if([elementName isEqualToString:@"title"]){
    self.currentItem.title = self.currentItemValue;
}

What is my issue, am I missing something?

1
  • you get the error for all rss? Commented Dec 19, 2011 at 0:50

1 Answer 1

12

The code provided looks good for me, what I would do first is to check if your RSS is valid. I think you have an RSS issue here. You can use the RSS Validation to make sure everything looks good.

I would recommend to sanitize your RSS, keep it very simple, if you only want to display news or articles use letters and numbers in your text and use SEO friendly URLs.

This will simplify the data you are loading from your app and avoid errors like special characters.

Try with a simple RSS with one entry to start and you will see if your code has errors.

2
  • i effectively have some rss errors on my file, let me try a simple one, anything special about it? just simple text?
    – Gabriel
    Commented Dec 19, 2011 at 1:02
  • 7
    holy crap, i spent the last 6 hours to figure out the problem with my code and it was my RSS. the sample you gave works, thanks
    – Gabriel
    Commented Dec 19, 2011 at 1:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.