首页 > 其他 > 详细

XML解析(简单)

时间:2014-09-15 03:23:09      阅读:296      评论:0      收藏:0      [点我收藏+]

 

  1. 获取解析文件路径
        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];


XML解析(简单)

原文:http://qccccc.blog.51cto.com/6004423/1552626

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!