这是从美团弄得xml文件,地区和经纬度。

你点了地区以后 ,  就可以查看经纬度 ,因为笔者懒, 有现成的文本框 , 所有偷懒了。

下面是一些枯燥的代码了 。

#import <UIKit/UIKit.h>
#import "RootTableViewController.h"
@interface AppDelegate : UIResponder @property (strong, nonatomic) UIWindow *window; @end
#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window.rootViewController=[[UINavigationController alloc] initWithRootViewController:[[RootTableViewController alloc] initWithStyle:UITableViewStyleGrouped]];
return YES;
}
#import <UIKit/UIKit.h>
#import "SecondViewController.h"
@interface RootTableViewController : UITableViewController<NSXMLParserDelegate> @property(strong,nonatomic)NSMutableArray *arr; @property(strong,nonatomic)NSMutableDictionary *dic1; @property(strong,nonatomic)NSString *str; @property(strong,nonatomic)NSMutableArray *arrname; @end
#import "RootTableViewController.h"

@interface RootTableViewController ()

@end

@implementation RootTableViewController

- (void)viewDidLoad {
[super viewDidLoad];
self.title=@"城市列表";
self.arrname=[NSMutableArray array]; NSURL *url=[NSURL URLWithString:@"http://www.meituan.com/api/v1/divisions?mtt=1.help%2Fapi.0.0.im7coqq1"];
NSData *data=[NSData dataWithContentsOfURL:url];
NSXMLParser *parser=[[NSXMLParser alloc]initWithData:data];
parser.delegate=self;
BOOL bol=[parser parse];
NSLog(@"%d",bol);
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"reuseIdentifier"];
}
/**
* 文档开始解析
*
* @param parser parser
*/
- (void)parserDidStartDocument:(NSXMLParser *)parser
{
self.arr=[NSMutableArray array];
}
/**
* 解析完毕
*
* @param parser parser
*/
- (void)parserDidEndDocument:(NSXMLParser *)parser
{
NSLog(@"%@",self.arr);
}
/**
* 文档元素 解析开始
*
* @param parser 解析的对象
* @param elementName 元素的名称
* @param namespaceURI 命名空间
* @param qName
* @param attributeDict 属性的字典
*/
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(nullable NSString *)namespaceURI qualifiedName:(nullable NSString *)qName attributes:(NSDictionary<NSString *, NSString *> *)attributeDict
{ if ([elementName isEqualToString:@"division"]) {
self.dic1=[NSMutableDictionary dictionary];
[self.dic1 setDictionary:attributeDict]; }
} /**
* 文档中元素 解析结束
*
* @param parser 解析的对象
* @param elementName 元素的名称
* @param namespaceURI 命名空间
* @param qName 属性的字典
*/
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(nullable NSString *)namespaceURI qualifiedName:(nullable NSString *)qName
{
if ([elementName isEqualToString:@"name"]||[elementName isEqualToString:@"latitude"]||[elementName isEqualToString:@"longitude"]) {
[self.dic1 setObject:self.str forKey:elementName];
}
else if ([elementName isEqualToString:@"division"])
{
[self.arr addObject:self.dic1];
}
}
/**
* 解析文件元素的内容
*
* @param parser 解析对象
* @param string 显示的文本内容
*/
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
self.str=string;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.arr.count;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuseIdentifier" forIndexPath:indexPath]; for (NSDictionary *dic in self.arr) {
[self.arrname addObject:dic[@"name"]];
} cell.textLabel.text=self.arrname[indexPath.row];
return cell;
} -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%@",self.arr[indexPath.row]);
SecondViewController *secondvc=[[SecondViewController alloc] init];
secondvc.strweidu=self.arr[indexPath.row][@"latitude"];
secondvc.strjindu=self.arr[indexPath.row][@"longitude"];
[self presentViewController:secondvc animated:YES completion:nil]; } @end
#import "ViewController.h"
#import "RootTableViewController.h"
@interface SecondViewController : ViewController
@property(strong,nonatomic)UILabel *lblname;
@property(strong,nonatomic)UILabel *lblpwd;
@property(strong,nonatomic)UITextField *name;
@property(strong,nonatomic)UITextField *pwd;
@property(strong,nonatomic)UIButton *buton;
@property(strong,nonatomic)NSString *strweidu;
@property(strong,nonatomic)NSString *strjindu; @end
#import "SecondViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (void)viewDidLoad {
[super viewDidLoad];
UIImageView *image=[[UIImageView alloc]initWithFrame:self.view.frame ];
[image setImage:[UIImage imageNamed:@"15EADA084F41FF349CED23058FD34D0E"]];
[self.view addSubview:image];
self.lblname=[[UILabel alloc]initWithFrame:CGRectMake(50, 200, 100, 50)];
self.lblname.text=@"精度";
[self.view addSubview:self.lblname];
self.lblpwd=[[UILabel alloc]initWithFrame:CGRectMake(50, 330, 100, 50)];
self.lblpwd.text=@"维度"; [self.view addSubview:self.lblpwd];
self.name=[[UITextField alloc] initWithFrame:CGRectMake(150, 200, 200, 50)];
[self.view addSubview:self.name]; self.name.text =self.strweidu; self.name.borderStyle=UITextBorderStyleRoundedRect;
self.pwd=[[UITextField alloc] initWithFrame:CGRectMake(150, 330, 200, 50)];
[self.view addSubview:self.pwd];
self.pwd.text=self.strjindu;
self.pwd.borderStyle=UITextBorderStyleRoundedRect;
self.buton=[[UIButton alloc] initWithFrame:CGRectMake(120, 400, 174, 66)];
self.buton.backgroundColor=[UIColor colorWithRed:0.532 green:1.000 blue:0.161 alpha:1.000];
self.buton.layer.cornerRadius=10;
[self.buton setTitle:@"确认" forState:0];
[self.buton setTitleColor:[UIColor whiteColor] forState:0];
[self.buton addTarget:self action:@selector(next) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.buton];
}
-(void)next
{
RootTableViewController *root=[[RootTableViewController alloc]init]; [self presentViewController:root animated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end

xml文件解析(解析以后在RootTableViewController输出)的更多相关文章

  1. 类的反射及xml文件的解析

    类的反射 xml文件的解析 .properties||.xml配置文件的创建及读取内容 //创建对象 Properties properties = new Properties(); //存储 pr ...

  2. JAVA读取XML文件并解析获取元素、属性值、子元素信息

    JAVA读取XML文件并解析获取元素.属性值.子元素信息 关键字 XML读取  InputStream   DocumentBuilderFactory   Element     Node 前言 最 ...

  3. 用SAX和PULL进行XML文件的解析与生成

    XML解析有传统的dom方法还有Jsoup,SAX,PULL等,这里讲的是比较省内存的SAX和PULL方法.Android中极力推荐用PULL的方式来解析,我个人觉得pull确实比较简单,但其内部的逻 ...

  4. JDOM方法实现对XML文件的解析

    首先要下载JDOM.jar包,下载地址:http://download.csdn.net/detail/ww6055/8880371 下载到JDOM.jar包之后导入到工程中去. 实例程序: book ...

  5. xml文件的解析

    1. xml文件的解析 void CDataMgr::readStringData() { std::string xml_name = "config/string.xml"; ...

  6. [置顶] Android开发之XML文件的解析

    Android系统开发之XML文件的解析 我们知道Http在网络传输中的数据组织方式有三种分别为:XML方式.HTML方式.JSON方式.其中XML为可扩展标记语言,如下: <?xml vers ...

  7. 【文件处理】xml 文件 DOM解析

    一.Java解析xml.解析xml四种方法.DOM.SAX.JDOM.DOM4j.XPath 此文针对其中的DOM方法具体展开介绍及代码分析 sax.dom是两种对xml文档进行解析的方法(没有具体实 ...

  8. Java中使用DOM4J来生成xml文件和解析xml文件

    一.前言 现在有不少需求,是需要我们解析xml文件中的数据,然后导入到数据库中,当然解析xml文件也有好多种方法,小编觉得还是DOM4J用的最多最广泛也最好理解的吧.小编也是最近需求里遇到了,就来整理 ...

  9. 【Android】XML文件的解析

    1.首先我们可以在res包路径下创建一个raw包,然后在raw下创建一个email.xml 文件,并修改其内容如下: <?xml version="1.0" encoding ...

  10. xml文件以及解析

    1.创建一个xml文件 <?xml version="1.0" encoding="UTF-8"?> <!-- xml:是一个可扩展的标记语言 ...

随机推荐

  1. 40个Java多线程问题总结

    前言 Java多线程分类中写了21篇多线程的文章,21篇文章的内容很多,个人认为,学习,内容越多.越杂的知识,越需要进行深刻的总结,这样才能记忆深刻,将知识变成自己的.这篇文章主要是对多线程的问题进行 ...

  2. 修复IE11首页被恶意篡改的问题

    前几天为了测试一个程序,把系统换成了Windows10,Windows10自带了微软的新浏览器Edge和IE11,用来其实也没什么太多感觉了,我习惯于Chrome,但有些东西还是得用IE,比如网银之类 ...

  3. 小丁带你走进git世界五-远程仓库

    一.文件,指令讲解 首先讲一下远程仓库和本地仓库在文件上面的区别,首先我们来看下对比图(当然这里说的区别是在于.git文件下面的文件内容,至于里面内容我们不会关注)這裡我们进行了相同的操作就是本地仓库 ...

  4. 基于java的分布式爬虫

    分类 分布式网络爬虫包含多个爬虫,每个爬虫需要完成的任务和单个的爬行器类似,它们从互联网上下载网页,并把网页保存在本地的磁盘,从中抽取URL并沿着这些URL的指向继续爬行.由于并行爬行器需要分割下载任 ...

  5. Binder In Native

    关于Binder的设计思想与Driver层实现细节可以看这个:Android Binder设计与实现 - 设计篇,这里首先简要概括一下. Service的每个Binder实体位于Service所属的进 ...

  6. Python学习--05函数

    Python函数 函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段. 函数能提高应用的模块性,和代码的重复利用率.我们已经知道Python提供了许多内建函数,比如print().但我们 ...

  7. Atitit java c# php c++ js跨语言调用matlab实现边缘检测等功能attilax总结

    Atitit java c# php c++ js跨语言调用matlab实现边缘检测等功能attilax总结 1.1. 边缘检测的基本方法Canny最常用了1 1.2. 编写matlab边缘检测代码, ...

  8. GDB 多线程调试:只停止断点的线程,其他线程任然执行; 或只运行某些线程 其他线程中断

    多线程调试之痛 调试器(如VS2008和老版GDB)往往只支持all-stop模式,调试多线程程序时,如果某个线程断在一个断点上,你的调试器会让整个程序freeze,直到你continue这个线程,程 ...

  9. 使用topshelf包装redis为windows服务

           Redis服务端目前用的是控制台程序运行,部署的时候能作为windows服务后台运行感觉更好.找到一篇文章Running Redis as a Windows Service,利用win ...

  10. ElasticSearch 5学习(4)——简单搜索笔记

    空搜索: GET /_search hits: total 总数 hits 前10条数据 hits 数组中的每个结果都包含_index._type和文档的_id字段,被加入到_source字段中这意味 ...