-1

I have developed one application to fetch RSS feed. I am getting this error code 5 for some URLs where as som others are working fine.

I know this error means the xml is invalid. But for my app, I have not written any xml files by my own.

Please tell me the probable reasons for this and let me know the solution

import "RootViewController.h"

@implementation RootViewController

  • (void)viewDidAppear:(BOOL)animated{

[super viewDidAppear:animated];

if ([stories count] == 0) {

    path = @"http://172.19.58.108:8080/jwplayer/JSP/Videolist.jsp";
    [self parseXMLFileAtURL:path];
}

}

-(void)parseXMLFileAtURL:(NSString *)URL{

stories = [[NSMutableArray alloc]init];
NSURL *xmlURL = [NSURL URLWithString:URL];
rssParser = [[NSXMLParser alloc]initWithContentsOfURL:xmlURL];
[rssParser setDelegate:self];
[rssParser setShouldProcessNamespaces:NO];
[rssParser setShouldReportNamespacePrefixes:NO];
[rssParser setShouldResolveExternalEntities:NO];
[rssParser parse];

}

-(void)parserDidStartDocument:(NSXMLParser *)parser{

NSLog(@"Found file and started parsing");

}

-(void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError{

NSString *errorString = [NSString stringWithFormat:@"Unable to download story feed from website (Error Code %i)", [parseError code]];
NSLog(@"Error parsing xml: %@", errorString);
UIAlertView *errorAlert = [[UIAlertView alloc]initWithTitle:@"Error loading content" message:errorString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];

}

-(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];
    currentTitle = [[NSMutableString alloc]init];
    currentDate = [[NSMutableString alloc]init];
    currentSummary = [[NSMutableString alloc]init];
    currentLink = [[NSMutableString alloc]init];
}

}

-(void)parser: (NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{

if ([elementName isEqualToString:@"item"]) {
    
    [item setObject:currentTitle forKey:@"title"];
    [item setObject:currentDate forKey:@"date"];
    [item setObject:currentSummary forKey:@"summary"];
    [item setObject:currentLink forKey:@"link"];
    [stories addObject:[item copy]];
    NSLog(@"adding story: %@", currentTitle);
}

}

-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{

if ([currentElement isEqualToString:@"title"]) {
    
    [currentTitle appendString:string];
}
else if ([currentElement isEqualToString:@"link"]) {
    
    [currentLink appendString:string];
}
else if ([currentElement isEqualToString:@"description"]) {
    
    [currentSummary appendString:string];
}
else if ([currentElement isEqualToString:@"pubDate"]) {
    
    [currentDate appendString:string];
}

}

-(void)parserDidEndDocument:(NSXMLParser *)parser{

[activityIndicator stopAnimating];
[activityIndicator removeFromSuperview];
NSLog(@"all done");
NSLog(@"stories array has %d items", [stories count]);
[newsTable reloadData];

}

Community
  • 1
  • 1

1 Answers1

-1

Please check your library class for Rss feed parsing. Use standard library class, change the the code accordingly.

user9930
  • 147
  • 3