求助:Three20 使用TTURLXMLResponse 获取XML问题
来源:互联网 发布:建筑软件大全 编辑:程序博客网 时间:2024/05/04 15:36
求助:Three20 使用TTURLXMLResponse 获取XML问题
在写一个xml读取数据的程序。使用了 TTURLXMLResponse 这个 Three20 扩展。
根据网上找出的各种源码,已能成功读取远端的XML内容,但获取的内容 是一个 NSDictionary 对象,内容完全不象XML返回的内容
也许 NSDictionary 可以处理与读取,但我不会,向大家求助。
XML源码:
复制代码
很普通的XML
获取部分的源码
复制代码
打印出来 feed 的内容,应该是正确获取了,但如何处理,不清楚该怎么做
复制代码
根据网上找出的各种源码,已能成功读取远端的XML内容,但获取的内容 是一个 NSDictionary 对象,内容完全不象XML返回的内容
也许 NSDictionary 可以处理与读取,但我不会,向大家求助。
XML源码:
复制代码
- <?xml version="1.0" encoding="UTF-8"?>
- <rss version="2.0">
- <magazines>
- <magazine>
- <id>1</id>
- <bid>0050</bid>
- <title>Sourcing Magazine111111</title>
- <catalogId>1</catalogId>
- <img_57>http://192.168.1.2/iphone/images/icon_57.jpg</img_57>
- <img_75>http://192.168.1.2/iphone/images/icon_320.jpg</img_75>
- <link>http://192.168.1.2/iphone/zip/0001.zip</link>
- <fileSize>20,000,000Byte</fileSize>
- <description>This is Description in the Magazine</description>
- <pubDate>2011-05-30 17:58:45</pubDate>
- <preimg1>http://192.168.1.2/iphone/images/preimg1.jpg</preimg1>
- <preimg2>http://192.168.1.2/iphone/images/preimg2/*.jpg</preimg2>
- <preimg3>http://192.168.1.2/iphone/images/preimg3.jpg</preimg3>
- </magazine>
- <magazine>
- <id>2</id>
- <bid>0050</bid>
- <title>Sourcing Magazine2222</title>
- <catalogId>1</catalogId>
- <img_57>http://192.168.1.2/iphone/images/icon_57.jpg</img_57>
- <img_75>http://192.168.1.2/iphone/images/icon_320.jpg</img_75>
- <link>http://192.168.1.2/iphone/zip/0001.zip</link>
- <fileSize>20,000,000Byte</fileSize>
- <description>This is Description in the Magazine</description>
- <pubDate>2011-05-30 17:58:45</pubDate>
- <preimg1>http://192.168.1.2/iphone/images/preimg1.jpg</preimg1>
- <preimg2>http://192.168.1.2/iphone/images/preimg2.jpg</preimg2>
- <preimg3>http://192.168.1.2/iphone/images/preimg3.jpg</preimg3>
- </magazine>
- <magazine>
- <id>3</id>
- <bid>0050</bid>
- <title>Sourcing Magazine333</title>
- <catalogId>1</catalogId>
- <img_57>http://192.168.1.2/iphone/images/icon_57.jpg</img_57>
- <img_75>http://192.168.1.2/iphone/images/icon_320.jpg</img_75>
- <link>http://192.168.1.2/iphone/zip/0001.zip</link>
- <fileSize>20,000,000Byte</fileSize>
- <description>This is Description in the Magazine</description>
- <pubDate>2011-05-30 17:58:45</pubDate>
- <preimg1>http://192.168.1.2/iphone/images/preimg1.jpg</preimg1>
- <preimg2>http://192.168.1.2/iphone/images/preimg2/*.jpg</preimg2>
- <preimg3>http://192.168.1.2/iphone/images/preimg3.jpg</preimg3>
- </magazine>
- </magazines>
- </rss>
很普通的XML
获取部分的源码
复制代码
- //读取,发送请求
- - (void)load:(TTURLRequestCachePolicy)cachePolicy more:(BOOL)more {
- if (!self.isLoading && TTIsStringWithAnyText(_searchQuery)) {
- NSString* url = @"http://192.168.1.2/iphone/magazine.xml";
- TTURLRequest* request = [TTURLRequest
- requestWithURL: url
- delegate: self];
- request.cachePolicy = cachePolicy;
- request.cacheExpirationAge = TT_CACHE_EXPIRATION_AGE_NEVER;
- TTURLXMLResponse* response = [[TTURLXMLResponse alloc] init];
- response.isRssFeed = YES;
- request.response = response;
- TT_RELEASE_SAFELY(response);
- [request send];
- }
- }
- //请求完成后,返回的内容处理
- - (void)requestDidFinishLoad:(TTURLRequest*)request {
- //获得接收的内容,处理
- TTURLXMLResponse* response = request.response;
- TTDASSERT([response.rootObject isKindOfClass:[NSDictionary class]]);
- NSDictionary* feed = response.rootObject;
- //打印这个 NSDictionary 对象
- NSLog(@"%@",feed);
- /*
- 这里是处理获得内容的地方,不会写。
- */
- //如果处理完成,请把获得的内容打成数组,然后显示到页面上
- NSMutableArray* feeds = [[NSMutableArray alloc] init];
- Magazine* f = [[Magazine alloc] init];
- f.subject = @"Magazine"; //这里是最终读取的xml上的内容,为了显示,写死了
- f.description = @"this is description";
- f.img_57 = @"http://192.168.1.2/iphone/images/icon_57.jpg";
- [feeds addObject:f];
- _feeds = feeds;
- [super requestDidFinishLoad:request];
- }
打印出来 feed 的内容,应该是正确获取了,但如何处理,不清楚该怎么做
复制代码
- {
- "___Entity_Name___" = rss;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "\n \n";
- magazines = {
- "___Entity_Name___" = magazines;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "\n\n\n\n\n";
- magazine = (
- {
- "___Entity_Name___" = magazine;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "\n\t \n\t \n\t \n\t \n\t \n \n\t \n\t \n\t \n\t \n \n \n \n\t ";
- bid = {
- "___Entity_Name___" = bid;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = 0050;
- };
- catalogId = {
- "___Entity_Name___" = catalogId;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = 1;
- };
- description = {
- "___Entity_Name___" = description;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "This is Description in the Magazine";
- };
- fileSize = {
- "___Entity_Name___" = fileSize;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "20,000,000Byte";
- };
- id = {
- "___Entity_Name___" = id;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = 1;
- };
- "img_57" = {
- "___Entity_Name___" = "img_57";
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "http://192.168.1.2/iphone/images/icon_57.jpg";
- };
- "img_75" = {
- "___Entity_Name___" = "img_75";
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "http://192.168.1.2/iphone/images/icon_320.jpg";
- };
- link = {
- "___Entity_Name___" = link;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "http://192.168.1.2/iphone/zip/0001.zip";
- };
- preimg1 = {
- "___Entity_Name___" = preimg1;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "http://192.168.1.2/iphone/images/preimg1.jpg";
- };
- preimg2 = {
- "___Entity_Name___" = preimg2;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "http://192.168.1.2/iphone/images/preimg2/*.jpg";
- };
- preimg3 = {
- "___Entity_Name___" = preimg3;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "http://192.168.1.2/iphone/images/preimg3.jpg";
- };
- pubDate = {
- "___Entity_Name___" = pubDate;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "2011-05-30 17:58:45";
- };
- title = {
- "___Entity_Name___" = title;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "Sourcing Magazine111111";
- };
- },
- {
- "___Entity_Name___" = magazine;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "\n\t \n\t \n\t \n\t \n\t \n \n\t \n\t \n\t \n\t \n \n \n \n\t ";
- bid = {
- "___Entity_Name___" = bid;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = 0050;
- };
- catalogId = {
- "___Entity_Name___" = catalogId;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = 1;
- };
- description = {
- "___Entity_Name___" = description;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "This is Description in the Magazine";
- };
- fileSize = {
- "___Entity_Name___" = fileSize;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "20,000,000Byte";
- };
- id = {
- "___Entity_Name___" = id;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = 2;
- };
- "img_57" = {
- "___Entity_Name___" = "img_57";
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "http://192.168.1.2/iphone/images/icon_57.jpg";
- };
- "img_75" = {
- "___Entity_Name___" = "img_75";
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "http://192.168.1.2/iphone/images/icon_320.jpg";
- };
- link = {
- "___Entity_Name___" = link;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "http://192.168.1.2/iphone/zip/0001.zip";
- };
- preimg1 = {
- "___Entity_Name___" = preimg1;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "http://192.168.1.2/iphone/images/preimg1.jpg";
- };
- preimg2 = {
- "___Entity_Name___" = preimg2;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "http://192.168.1.2/iphone/images/preimg2/*.jpg";
- };
- preimg3 = {
- "___Entity_Name___" = preimg3;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "http://192.168.1.2/iphone/images/preimg3.jpg";
- };
- pubDate = {
- "___Entity_Name___" = pubDate;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "2011-05-30 17:58:45";
- };
- title = {
- "___Entity_Name___" = title;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "Sourcing Magazine2222";
- };
- },
- {
- "___Entity_Name___" = magazine;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "\n\t \n\t \n\t \n\t \n\t \n \n\t \n\t \n\t \n\t \n \n \n \n\t ";
- bid = {
- "___Entity_Name___" = bid;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = 0050;
- };
- catalogId = {
- "___Entity_Name___" = catalogId;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = 1;
- };
- description = {
- "___Entity_Name___" = description;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "This is Description in the Magazine";
- };
- fileSize = {
- "___Entity_Name___" = fileSize;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "20,000,000Byte";
- };
- id = {
- "___Entity_Name___" = id;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = 3;
- };
- "img_57" = {
- "___Entity_Name___" = "img_57";
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "http://192.168.1.2/iphone/images/icon_57.jpg";
- };
- "img_75" = {
- "___Entity_Name___" = "img_75";
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "http://192.168.1.2/iphone/images/icon_320.jpg";
- };
- link = {
- "___Entity_Name___" = link;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "http://192.168.1.2/iphone/zip/0001.zip";
- };
- preimg1 = {
- "___Entity_Name___" = preimg1;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "http://192.168.1.2/iphone/images/preimg1.jpg";
- };
- preimg2 = {
- "___Entity_Name___" = preimg2;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "http://192.168.1.2/iphone/images/preimg2/*.jpg";
- };
- preimg3 = {
- "___Entity_Name___" = preimg3;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "http://192.168.1.2/iphone/images/preimg3.jpg";
- };
- pubDate = {
- "___Entity_Name___" = pubDate;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "2011-05-30 17:58:45";
- };
- title = {
- "___Entity_Name___" = title;
- "___Entity_Type___" = unknown;
- "___Entity_Value___" = "Sourcing Magazine3333";
- };
- }
- );
- };
- version = "2.0";
- }
自己研究。终于解决。源码奉上
//读取进程
- (void)load:(TTURLRequestCachePolicy)cachePolicy more:(BOOL)more {
if (!self.isLoading && TTIsStringWithAnyText(_searchQuery)) {
NSString* url = @"http://192.168.1.2/iphone/magazine.xml";
TTURLRequest* request = [TTURLRequest
requestWithURL: url
delegate: self];
request.cachePolicy = cachePolicy;
request.cacheExpirationAge = TT_CACHE_EXPIRATION_AGE_NEVER;
TTURLXMLResponse* response = [[TTURLXMLResponse alloc] init];
response.isRssFeed = YES;
request.response = response;
TT_RELEASE_SAFELY(response);
[request send];
}
}
- (void)requestDidFinishLoad:(TTURLRequest*)request {
TTURLXMLResponse *response = request.response;
TTDASSERT([response.rootObject isKindOfClass:[NSDictionary class]]);
NSDictionary * rootObject = response.rootObject;
TTDASSERT([[rootObject objectForKey:@"channel"] isKindOfClass:[NSDictionary class]]);
NSDictionary *channel = [rootObject objectForKey:@"channel"];
TTDASSERT([[channel objectForKey:@"item"] isKindOfClass:[NSDictionary class]]);
NSMutableArray* feeds = [[NSMutableArray alloc] init];
NSArray* entries = [channel objectForKey:@"item"];
for(int i=0;i<[entries count];i++){
NSDictionary* entry = [entries objectAtIndex:i];
Magazine* d = [[Magazine alloc] init];
NSDictionary* v2 = [entry objectForKey:@"title"];
d.subject = [v2 objectForKey:@"___Entity_Value___"];
NSDictionary* v3 = [entry objectForKey:@"description"];
d.description = [v3 objectForKey:@"___Entity_Value___"];
NSDictionary* v4 = [entry objectForKey:@"img_57"];
d.img_57 = [v4 objectForKey:@"___Entity_Value___"];
[feeds addObject:d];
}
_feeds = feeds;
[super requestDidFinishLoad:request];
}
返回的是一整套的类似JSON格式的东东,要反复打碎,解析,最后搞定。
转: http://www.cocoachina.com/bbs/read.php?tid-61730.html
- 求助:Three20 使用TTURLXMLResponse 获取XML问题
- 使用Three20
- 使用Three20
- 关于Three20框架下的本地化不能使用的问题
- Three20 iOS 使用
- 求助 ! vs2005 Login 控件使用的问题~!
- Three20
- Three20
- Three20
- 求助问题
- 问题求助?
- 问题求助
- 使用 Three20 的经验分享
- 求助:关于后台获取时间,前台显示倒计时的问题
- 求助~异步联网获取图片,使用ViewPager进行显示?
- 求助~异步联网获取图片,使用ViewPager进行显示?
- Objectflickr and three20 两个超级问题
- three20配置中的一个小问题
- online Judge 百练 单词替换 2944
- 今天工作的内容found tag String where item is expected
- struts2学习笔记1
- Application framework
- ZOJ 1092 Arbitrage 【Floyd-Warshal】
- 求助:Three20 使用TTURLXMLResponse 获取XML问题
- MyEclipse7 creation of element failed org.eclipse.core.internal.registry.configurationelementhandle
- IMDB评分TOP250部给力电影
- Spring Jms入门实例
- 为什么std::valarray会很慢。
- 反编译Apk得到Java源代码
- 天融信top sec防火墙关于内外网ip映射配置
- 系统架构-UML 包图
- 字符替换 2700:字符替换