ios 解析xml文件怎么用tableview显示
1个回答
推荐于2016-10-05 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517198
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
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解析
chatLogParser release];
[self performSelectorOnMainThread:@selector(finshLoadFile) withObject:nil waitUntilDone:YES];//创建线程
[pool release];
}
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解析
chatLogParser release];
[self performSelectorOnMainThread:@selector(finshLoadFile) withObject:nil waitUntilDone:YES];//创建线程
[pool release];
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询