0

我有来自网站的 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" />。请帮帮我。

4

1 回答 1

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"];
}
于 2013-03-03T15:29:05.177 回答