用第三方框架GDataXMLNode解析XML数据:
2015-11-29 16:08
633 查看
用第三方框架GDataXMLNode解析XML数据:
(void)viewDidLoad
{
// 1.确定请求路径
NSURL *url = [NSURLURLWithString:@"http://120.25.226.186:32812/video?type=XML"];
// 2.创建请求对象
NSURLRequest *request = [NSURLRequest requestWithURL:url];
// 3.发送请求
[NSURLConnection connectionWithRequest:request delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
// 加载XML文档
GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:data options:kNilOptions error:nil];
// 拿到这个XML的根元素,并拿到这个根元素下面的所有名称为Video的子元素
NSArray *eles = [doc.rootElementelementsForName:@"video"];
// 遍历else数组,完成数据的转换
for (GDataXMLElement *ele in eles) {
// 创建模型
XMGVideo *video = [[XMGVideo alloc] init];
video.name = [ele attributeForName:@"name"].stringValue;
video.image = [ele attributeForName:@"image"].stringValue;
video.length = [ele attributeForName:@"length"].stringValue.integerValue;
video.url = [ele attributeForName:@"url"].stringValue;
video.ID = [ele attributeForName:@"id"].stringValue;
[self.videos addObject:video];
}
}
- (void)connectionDidFinishLoading:(NSURLConnection*)connection
{
// 刷新数据
[self<
9c69
span style="color:rgb(0,0,0);">.tableV reloadData];
}
(void)viewDidLoad
{
// 1.确定请求路径
NSURL *url = [NSURLURLWithString:@"http://120.25.226.186:32812/video?type=XML"];
// 2.创建请求对象
NSURLRequest *request = [NSURLRequest requestWithURL:url];
// 3.发送请求
[NSURLConnection connectionWithRequest:request delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
// 加载XML文档
GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:data options:kNilOptions error:nil];
// 拿到这个XML的根元素,并拿到这个根元素下面的所有名称为Video的子元素
NSArray *eles = [doc.rootElementelementsForName:@"video"];
// 遍历else数组,完成数据的转换
for (GDataXMLElement *ele in eles) {
// 创建模型
XMGVideo *video = [[XMGVideo alloc] init];
video.name = [ele attributeForName:@"name"].stringValue;
video.image = [ele attributeForName:@"image"].stringValue;
video.length = [ele attributeForName:@"length"].stringValue.integerValue;
video.url = [ele attributeForName:@"url"].stringValue;
video.ID = [ele attributeForName:@"id"].stringValue;
[self.videos addObject:video];
}
}
- (void)connectionDidFinishLoading:(NSURLConnection*)connection
{
// 刷新数据
[self<
9c69
span style="color:rgb(0,0,0);">.tableV reloadData];
}
相关文章推荐
- DOM----nodeType,nodeName,nodeValue笔记
- 《Node.js实战(第2季)》 读书笔记
- nodejs net模块实现socket
- nodeJs常用的一些地址
- [Nodejs入门]第四篇,用nodejs实现一个爬虫的功能
- [nodejs入门]第一篇,javascript基础(2)
- node.js和socket.io纯js实现的即时通讯实例分享
- 237. Delete Node in a Linked List
- Swap Nodes in Pairs
- ROS_hydro_catkin建立标准程序包_helloworld.h+helloworld.cpp+helloworldnode.cpp
- NodeManagerMetrics上精确化Container指标监控
- NodeJS中使用benchmark进行基准测试-@alsotang
- nodejs学习--子进程 child_process模块的基本介绍
- nodejs学习--util
- nodej-- Query String
- A new node couldn't be inserted because one with the same name exists. (VERR_CFGM_NODE_EXISTS)
- nodejs学习--path
- [转][自己打脸]Node.JS——NodeJS引用路径的小问题
- nodejs-url
- nodejs学习1---基础知识