我开发了一个应用程序来获取RSS提要。我收到了一些URL的错误代码5,其中som其他工作正常。
我知道这个错误意味着xml无效。但对于我的应用程序,我没有自己编写任何xml文件。
请告诉我可能的原因并让我知道解决方案
@implementation RootViewController
[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 *)解析器{
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)解析器:(NSXMLParser *)解析器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 *)解析器{
[activityIndicator stopAnimating];
[activityIndicator removeFromSuperview];
NSLog(@"all done");
NSLog(@"stories array has %d items", [stories count]);
[newsTable reloadData];
}
答案 0 :(得分:-1)
请检查您的库类以获取Rss Feed解析。使用标准库类,相应地更改代码。