我有来自网站的RSS页面。
<item>
<title>Запорожье: Вечер 03 Mar, Sun</title>
<link>http://www.gismeteo.ru/city/daily/5093/?462419</link>
<description>Облачно, температура 1..3 С, давление 753..755 мм рт.ст., ветер Юго-Западный, 6 м/с</description>
<category>Погода</category>
<enclosure url="http://img.gismeteo.ru/images/icons/new/d.sun.c2.png" length="2000" type="image/gif" />
<source url="http://informer.gismeteo.ru/rss/34601.xml">GISMETEO.RU: Погода в г. Запорожье</source>
<guid>418461</guid>
</item>
这是我的代码
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if([elementName isEqualToString:@"title"]){
xmlStringFileObject.titleString = nodecontent;
}
else if([elementName isEqualToString:@"description"]){
xmlStringFileObject.descriptionString = nodecontent;
}
else if([elementName isEqualToString:@"category"])
{
self.xmlStringFileObject.categoryString = nodecontent;
}
if([elementName isEqualToString:@"item"])
{
[outputData addObject:xmlStringFileObject];
}
nodecontent=[[NSMutableString alloc]init];
}
它工作正常但我无法解析图像并将其加载到UIImageView
我需要一个解析图像
<enclosure url="http://img.gismeteo.ru/images/icons/new/d.sun.c2.png" length="2000" type="image/gif" />
。请帮帮我。
答案 0 :(得分:0)
看看我是怎么做到的
NSString* imageURL = urlString; //http://img.gismeteo.ru/images/icons/new/d.sun.c2.png
NSData *imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:imageURL]];
UIImage *img = [[UIImage alloc] initWithData:imageData];Or you do not know how to get url string from xml?
UIImageView *imageView = [[UIImageView alloc] initWithImage:img];
或者您不知道如何从xml获取url字符串?
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
if([elementName isEqualToString:@"source"])
NSString *urlString = [attributeDict objectForKey:@"url"];
}