우리 대학의 iPad 신문 앱을 만들려고합니다. 우리의 시도는 NSXMLParser를 사용하여 신문의 웹 사이트에서 직접 파싱하는 것이 었습니다. 우리는 헤드 라인 분석에 성공했습니다. 내 말은 기사의 제목, 요약, 링크 및 게시일을 구문 분석 할 수 있다는 것입니다. 다음 단계는 각 기사의 본문을 파싱하여 각 기사의 몇 문장을 검색하여 레이아웃을 적용하는 것입니다. 그래서, 우리는 두 개의 파서 클래스를 만들기로 결정했습니다 : 하나는 헤드 라인을 파싱하기위한 클래스이고 다른 하나는 각 링크에서 기사를 파싱하기위한 클래스입니다. 앞서 언급했듯이 헤드 라인을 성공적으로 파싱 할 수 있지만 다른 파서 클래스 (InnerParser.m)에서는 NSURLConnection이 -1001 오류 코드 (시간 초과를 의미 함)로 실패합니다. 여기에 우리가 다른 웹 사이트를하려 할 때, 잘못된 링크를 의미하는 오류 코드 -1000, 실패오류 코드 -1001로 NSURLConnection이 실패합니다.
http://theaggie.org/rss/headlines.xml
newpaper 웹 사이트의 URL입니다. 여기에 해당 URL 나는 우리의 코드에서 뭔가 문제가 확실히있다 알고
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!
안녕하세요! 응답 해 주셔서 대단히 감사드립니다. 변수 url이 올바르게 정의 된 것 같습니다. 그 특정 URL을 콘솔에 기록하고 싶었습니다. 콘솔에 로그온하지만 오류 코드 -1000으로 인해 파서가 링크에 연결할 수 없습니다. 비공개 이메일로 보내면 Google 코드를 살펴 보시겠습니까? 다시 한번 감사드립니다. – SerPiero
다시 확인해야합니다. 그것은 당신의 URL이 XML 피드 이외의 다른 것들로 설정되었다는 이상한 것 같습니다. – esqew
안녕하세요. 우리는 이미 XML 피드를 파싱했습니다. 이제 우리는 각 링크에 들어가 HTML의 "BODY"를 파싱하려고합니다. – SerPiero