1
XML을 구문 분석하기위한 간단한 테스트 프로젝트를 만들었습니다. 이 테스트를 위해 앱에 .plist 파일을 만들었습니다. 나는 그것을 documentsDirectory에 복사한다. 파일이 복사 된 것을 볼 수 있습니다. 나는 NSXMLParser의있는 NSData 객체로 초기화 할 때 내가 얻을 :이 파일이 존재하지 않음을 알려줍니다NSData initWithContentsOfFile이 비어 있습니다.
The operation couldn’t be completed. (NSXMLParserErrorDomain error 4.)
. NSData가 nil이 아니며 fileExistsAtPath가 체크 아웃되어 있는지 확인했습니다. 나는 다음에 무엇을 시도해야할지 고집스럽게 생각합니다. 이견있는 사람? 감사.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self createEditableCopyOfDatabaseIfNeeded];
NSString *path = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"testList.plist"];
NSData *data = [[NSData alloc] initWithContentsOfFile:path];
if (data == nil) {
NSLog(@"yes nil");
}
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
parser.delegate = self;
[parser parse];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)createEditableCopyOfDatabaseIfNeeded
{
// First, test for existence.
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSString *writableDBPath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"testList.plist"];
success = [fileManager fileExistsAtPath:writableDBPath];
if (success) return;
// The writable database does not exist, so copy the default to the appropriate location.
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"testList.plist"];
success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
if (!success) {
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
}
- (NSString *)applicationDocumentsDirectory {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return documentsDirectory;
}
#pragma mark - NSXMLParserDelegate
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
if ([elementName isEqualToString:@"hg19Packet0.bin"]) {
NSLog(@"first");
}
}
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError {
NSLog(@"%@", [parseError localizedDescription]);
}
'NSLog ("data : % @", [[NSString alloc] initWithData : 데이터 인코딩 : NSUTF8StringEncoding]);'내용이 올바른지 확인하기 위해 데이터를 로그 아웃하십시오. – fzwo