1,首先获取文件目录
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
- NSString *documentsDirectory = [paths objectAtIndex:0];
- chatFile = [[NSString alloc] initWithString:[documentsDirectory stringByAppendingPathComponent:CHATSFILE_NAME]];
|
2,加载文件
- (void) loadThread:(NSString *)xmlFile {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSXMLParser *chatLogParser = [[NSXMLParser alloc] initWithContentsOfURL:[NSURLfileURLWithPath:xmlFile]];
[chatLogParser setDelegate:self];
[currentString setString:@""];//记录当前节点的值
[currentChatInfo removeAllObjects];//节点对象
[chatLogParser parse];//开始XML解析
[self performSelectorOnMainThread:@selector(finshLoadFile) withObject:nil waitUntilDone:YES];//创建线程
}
|
原文链接:https://www.f2er.com/xml/297594.html