我们正在努力为我们的大学制作一个iPad报纸应用程序。我们的尝试是使用NSXMLParser直接从报纸网站解析。我们成功地解析了头条新闻。我的意思是我们可以解析文章的标题,摘要,链接和pubDate。我们的下一步是解析每篇文章的正文,以便我们可以从每篇文章中检索几个句子以进行布局。因此,我们决定创建两个解析器类:一个用于解析标题,另一个用于解析每个链接中的文章。正如我之前提到的,我们可以成功解析标题,但是在我们的其他解析器类(InnerParser.m)中,NSURLConnection失败,错误代码为-1001,这意味着超时。这是新闻网站的网址
http://theaggie.org/rss/headlines.xml
当我们尝试其他网站时,它会失败,错误代码为-1000,这意味着链接不正确。这是该网址
http://www.hiddenelephant.com/blog/feed/rss/
我知道我们的代码肯定存在问题,但我们无法理解。这是我在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 :(得分:0)
变量url
是否正确定义?如果我正确地阅读了您的代码,那么您应该NSLog()
ging您似乎想要成为XML文件的url
变量。但是,从您的控制台输出中,您的url
变量似乎设置为:
http://theaggie.org/article/2011/04/07/federal-government-cites-uc-davis-for-animal-cruelty
我在这里遗漏了什么吗?这应该是这样吗?
答案 1 :(得分:0)
在我的案例中,问题出在第三方库 - FirebasePerformance
。
问题网址:Dockerfile