[cocoa]_[初级]_[解析XML文件获取数据]
发布时间:2020-12-16 06:09:56 所属栏目:百科 来源:网络整理
导读:场景:获取配置文件中某些数据用于程序某个功能的应用。 +(void) OpenXmlFile{ NSString *optionPath =@"/Users/mac/work/pratise/12.xml"; NSURL *furl = [NSURL fileURLWithPath:optionPath]; NSXMLDocument * xmlDoc = [[NSXMLDocument alloc]initWithCon
场景:获取配置文件中某些数据用于程序某个功能的应用。 +(void) OpenXmlFile { NSString *optionPath =@"/Users/mac/work/pratise/12.xml"; NSURL *furl = [NSURL fileURLWithPath:optionPath]; NSXMLDocument * xmlDoc = [[NSXMLDocument alloc]initWithContentsOfURL:furl options:(NSXMLNodePreserveWhitespace|NSXMLNodePreserveCDATA) error:nil]; [xmlDoc autorelease]; NSXMLElement *root = [xmlDoc rootElement]; NSXMLElement *family =(NSXMLElement*)[root childAtIndex:0]; NSLog(@"%@",family.stringValue); NSXMLElement *friend =(NSXMLElement*)[root childAtIndex:1]; NSLog(@"%@",friend.stringValue); NSXMLElement *classmate =(NSXMLElement*)[root childAtIndex:2]; NSLog(@"%@",classmate.stringValue); NSXMLElement *worker =(NSXMLElement*)[root childAtIndex:3]; NSLog(@"%@",worker.stringValue); NSXMLElement *fellowVillager =(NSXMLElement*)[root childAtIndex:4]; NSLog(@"%@",fellowVillager.stringValue); NSXMLElement *stranger =(NSXMLElement*)[root childAtIndex:5]; NSLog(@"%@",stranger.stringValue); } 运行结果:
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |