2011-04-09 209 views
1

我們正試圖爲我們的大學制作iPad報紙應用程序。我們的嘗試是使用NSXMLParser從報紙網站直接解析。我們成功地解析了頭條新聞。我的意思是我們可以解析文章的標題,摘要,鏈接和pubDate。下一步是解析每篇文章的主體,以便我們可以從每篇文章中檢索幾個句子以進行佈局。因此,我們決定創建兩個解析器類:一個用於解析標題,另一個用於解析每個鏈接中的文章。正如我前面提到的,我們可以成功地解析標題,但是在我們的其他解析器類(InnerParser.m)中,NSURLConnection失敗,錯誤代碼爲-1001,這意味着超時。這裏是報刊文字網站NSURLConnection失敗,錯誤代碼爲-1001

http://theaggie.org/rss/headlines.xml

當我們嘗試另一個網站時,出現錯誤代碼-1000,它意味着壞鏈接的URL。下面是URL

​​

我知道肯定有什麼問題在我們的代碼,但我們無法弄清楚。這是我在stackoverflow上的第一篇文章。我不知道我應該發佈多少代碼。我將包含來自控制檯的一些代碼和日誌。如果這些還不夠,我願意將我們的整個代碼展示給那些可以慷慨地與我們分享知識的人。任何幫助將不勝感激。謝謝大家。

這裏是我們得到錯誤

- (void)parseRssFeed:(NSString *)url withDelegate:(id)aDelegate { 
[self setDelegate:aDelegate]; 

NSLog(@"*****************************************************************************************"); 
NSLog(@"Inner parser link:%@", url); 
NSLog(@"*****************************************************************************************"); 

storyData = [[NSMutableData data] retain]; 

NSURL *baseURL = [[NSURL URLWithString:url] retain]; 

NSLog(@"Step 1: What about Here!"); 

NSURLRequest *request = [NSURLRequest requestWithURL:baseURL]; 

NSLog(@"Step 2: What about Here!"); 

[[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease]; 

NSLog(@"Step 3: What about Here!"); 

} 

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{ 
NSLog(@"Did Recieve Response!?"); 
[storyData setLength:0]; 
} 

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{ 
NSLog(@"Did Recieve Data!?"); 
[storyData appendData:data]; 
} 

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
{ 
NSString * errorString = [NSString stringWithFormat:@"Unable to download xml data (Error code %i)", [error code]]; 

UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Error loading content" message:errorString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
[errorAlert show]; 
} 

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 

NSLog(@"Did Finish Loading!?"); 

self.news = [[Story alloc] init]; 

NSXMLParser *storyParser = [[NSXMLParser alloc] initWithData:storyData];//story source code now contained in storyData 

[storyParser setDelegate:self]; // May need to change the name of rssParser to something else 

[storyParser parse]; 

} 

代碼這裏是從控制檯某些日誌

2011-04-08 20:34:51.936 TheCalAggie[794:207] Parsing started for article! 
2011-04-08 20:34:51.938 TheCalAggie[794:207] Adding story title: Aggie Daily Calendar 
2011-04-08 20:34:51.938 TheCalAggie[794:207] From the link: http://theaggie.org/article/2011/04/07/aggie-daily-calendar 
2011-04-08 20:34:51.939 TheCalAggie[794:207] Summary: TODAY: Challah For Hunger; Shinkoskey Noon Concert: Zoila Muñoz; Student Services and Fees Administrative Advisory Committee 
2011-04-08 20:34:51.940 TheCalAggie[794:207] Published on: Thu, 07 Apr 2011 00:00:00 -0700 
2011-04-08 20:34:51.941 TheCalAggie[794:207] ====================== 
2011-04-08 20:34:51.942 TheCalAggie[794:207] STARTING STORY PARSER! 
2011-04-08 20:34:51.942 TheCalAggie[794:207] ====================== 
2011-04-08 20:34:51.943 TheCalAggie[794:207] Parsing started for article! 
2011-04-08 20:34:51.944 TheCalAggie[794:207] Adding story title: Becoming an undergraduate researcher 
2011-04-08 20:34:51.945 TheCalAggie[794:207] From the link: http://theaggie.org/article/2011/04/07/becoming-an-undergraduate-researcher 
2011-04-08 20:34:51.946 TheCalAggie[794:207] Summary: Researching as an undergraduate can provide opportunities for those pursuing post-graduate study and experience working in a specific field. 
2011-04-08 20:34:51.946 TheCalAggie[794:207] Published on: Thu, 07 Apr 2011 00:00:00 -0700 
2011-04-08 20:34:51.947 TheCalAggie[794:207] ====================== 
2011-04-08 20:34:51.948 TheCalAggie[794:207] STARTING STORY PARSER! 
2011-04-08 20:34:51.949 TheCalAggie[794:207] ====================== 
2011-04-08 20:34:51.950 TheCalAggie[794:207] Parsing started for article! 
2011-04-08 20:34:51.951 TheCalAggie[794:207] Adding story title: Aggie Daily Calendar 
2011-04-08 20:34:51.952 TheCalAggie[794:207] From the link: http://theaggie.org/article/2011/04/06/aggie-daily-calendar 
2011-04-08 20:34:51.953 TheCalAggie[794:207] Summary: Veggie Bed Prep Workshop; French Club Meeting; Third Street Improvements Final Community Workshop; Delta Epsilon Mu Games Night; The Spokes Auditions; Bistro 33 Poetry Night Reading Series. 
2011-04-08 20:34:51.954 TheCalAggie[794:207] Published on: Wed, 06 Apr 2011 00:00:00 -0700 
2011-04-08 20:34:51.955 TheCalAggie[794:207] ====================== 
2011-04-08 20:34:51.956 TheCalAggie[794:207] STARTING STORY PARSER! 
2011-04-08 20:34:51.957 TheCalAggie[794:207] ====================== 
2011-04-08 20:34:51.957 TheCalAggie[794:207] We recieved the article! 
2011-04-08 20:34:51.958 TheCalAggie[794:207] Article: *nil description* 
2011-04-08 20:34:51.959 TheCalAggie[794:207] What is in sections: (
(null) 
) 
2011-04-08 20:34:51.963 TheCalAggie[794:207] ***************************************************************************************** 
2011-04-08 20:34:51.965 TheCalAggie[794:207] Inner parser link:http://theaggie.org/article/2011/04/07/federal-government-cites-uc-davis-for-animal-cruelty 
2011-04-08 20:34:51.966 TheCalAggie[794:207] ***************************************************************************************** 
2011-04-08 20:34:51.966 TheCalAggie[794:207] Step 1: What about Here! 
2011-04-08 20:34:51.967 TheCalAggie[794:207] Step 2: What about Here! 
2011-04-08 20:34:51.968 TheCalAggie[794:207] Step 3: What about Here! 
2011-04-08 20:34:51.976 TheCalAggie[794:207] Parsing is done Parser class! 

回答

0

是變量url正確定義?如果我正確地讀取了你的代碼,你應該是NSLog(),你的url變量,你似乎想成爲你的XML文件。不過,從控制檯輸出,它看起來像你的url變量設置爲這樣的:這裏

http://theaggie.org/article/2011/04/07/federal-government-cites-uc-davis-for-animal-cruelty 

我這麼想嗎?這應該是這樣嗎?

+0

嗨esqew! 非常感謝您的回覆。我認爲變量url是正確定義的。我想在控制檯上記錄該特定的網址。它在控制檯上登錄,但由於錯誤代碼爲-1000,我們的解析器無法連接到鏈接。 如果我將它發送到您的私人電子郵件,您是否介意查看我們的代碼?再次感謝。 – SerPiero 2011-04-13 06:17:06

+0

您應該仔細檢查。這似乎很奇怪,你的網址被設置爲別的東西*除了你的XML feed。 – esqew 2011-04-13 19:32:16

+0

再次嗨。我們已經解析了XML Feed。現在,我們試圖進入每個鏈接並解析HTML的「BODY」。 – SerPiero 2011-04-14 00:27:57

相關問題