XMLReader 클래스를 사용하여 URL의 일부 XML을 구문 분석하고 있습니다. XML은 성공적으로 때때로 구문 분석, 때로는 내가 얻을 :NSXMLParser는 NSData 입력이 항상 같을 때만 오류 코드 4를 제공합니다.
오류 도메인 = NSXMLParserErrorDomain 코드 = 4 "작업을 완료 할 수 없습니다 (NSXMLParserErrorDomain 오류 4.)."
는 구문 분석은 일반적으로 첫 번째 성공 나는 뭔가를 바꾼 후에 그것을 실행하고, 나는 그 밖의 것을 바꿀 때까지 실패한다. 예를 들어, 아래 코드에서 [parser release] 행을 주석 처리하고 성공적으로 구문 분석했습니다. 그런 다음 다시 실행하고 오류 코드 4로 돌아갑니다.
매번 성공하거나 실패 할 때마다 동일한 입력 데이터를 기록합니다.
어떤 아이디어가 잘못 되었나요? 도움이된다면 더 많은 코드를 붙여 넣을 수 있지만 항상 동일한 데이터를 받기 때문에 NSXMLParser 구문 분석 메서드 (아래 코드 참조) 내에 오류가 격리되어 있습니다.
감사합니다.
편집 : 오류 코드 4는 빈 문서 오류입니다. 하지만 NSData가 비어 있지 않다는 것을 알고 있습니다. 그래서 다른 여기
- (NSDictionary *)objectWithData:(NSData *)data
{
//data always makes it here, the same data gets logged regardless of parse success
//NSLog(@"%@",data);
// Clear out any old data
[dictionaryStack release];
[textInProgress release];
dictionaryStack = [[NSMutableArray alloc] init];
textInProgress = [[NSMutableString alloc] init];
// Initialize the stack with a fresh dictionary
[dictionaryStack addObject:[NSMutableDictionary dictionary]];
// Parse the XML
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
parser.delegate = self;
[parser setShouldResolveExternalEntities:NO];
BOOL success = [parser parse];
[parser release];
// Return the stack's root dictionary on success
if (success)
{
NSDictionary *resultDict = [dictionaryStack objectAtIndex:0];
return resultDict;
}
return nil;
}
당신이'NSLog ("@"% d 개 ", [데이터 길이])를 추가 시겠어요;?. 호출하기 전에''initWithData' – dasblinkenlight
물론 그것은 당신이 오류를 얻을 때 2008 – Joe
심지어 2008을 반환합니까 반환 – dasblinkenlight