XML解析(简单)
获取解析文件路径
NSString * xmlPath = [[NSBundle mainBundle] pathForResource:@"Citys" ofType:@"xml"];
2.初始化xml字符串
NSString * xmlStr = [NSString stringWithContentsOfFile:xmlPath encoding:NSUTF8StringEncoding error:nil];
3.初始化一个GDataXMLDocument对象 , 因为解析时所有的内容都是从该对象中获取,(所以需要将要解析的内容放入该对象)
self.document = [[GDataXMLDocument alloc]initWithXMLString:xmlStr options:0 error:nil];
self.city = [self.document nodesForXPath:@"//name" error:nil];
self.latitude = [self.document nodesForXPath:@"//latitude_e6" error:nil];
self.longitude = [self.document nodesForXPath:@"//longitude_e6" error:nil];
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。