XML解析(简单)

 

  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,解析)