+(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); }
运行结果:
原文链接:https://www.f2er.com/xml/296229.html