2011-11-22 105 views
-1

我開發了一個應用程序來獲取RSS提要。我得到這個錯誤代碼5的一些網址,因爲其他人工作正常。錯誤代碼5在應用程序

我知道這個錯誤意味着xml無效。但對於我的應用程序,我沒有自己編寫任何xml文件。

請告訴我這種情況的原因大概讓我知道解決的辦法

進口 「RootViewController.h」

@implementation RootViewController的

  • (無效)viewDidAppear:(BOOL)動畫{

[super viewDidAppear:animated];

如果([故事計數] == 0){

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

}

- (無效)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"); 

}

- (無效)解析器:(的NSXMLParser *)解析器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]; 

}

- (無效)解析器:(的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]; 
} 

}

- (無效)解析器:(的NSXMLParser *)解析器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); 
} 

}

- (無效)解析器:(的NSXMLParser *)解析器foundCharacters:(的NSString *)串{

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

}

- (空)parserDidEndDocument:(*的NSXMLParser)分析器{

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

}

+0

發送給我們的鏈接到RSS訂閱源,並將您的XML解析代碼添加到問題:) – deanWombourne

+0

代碼如上.....鏈接不能共享,因爲它在我的辦公網絡上 –

+0

您可以嘗試格式化它還有一點 - 你的問題幾乎是不可讀的;) – deanWombourne

回答

-1

請檢查RSS訂閱您解析庫類。使用標準庫類,相應地更改代碼。

相關問題