vasilenkoigor
vasilenkoigor

Reputation: 27

Parse image in RSS iOS

guys. Please help me... I'm parsing this RSS channel

<item><title>Более 100 военных запаса после учений пошли на контрактную службу</title><link>http://www.ria.ru/defense_safety/20141004/1026910957.html</link><guid>http://www.ria.ru/defense_safety/20141004/1026910957.html</guid><rian:related xmlns:rian="http://rian.ru"><rian:url>http://ria.ru/export/rss2/defense_safety/20140923/1025254076.xml</rian:url></rian:related><rian:priority xmlns:rian="http://rian.ru">3</rian:priority><pubDate>Sat, 04 Oct 2014 14:33:00 +0400</pubDate><description>Первый заместитель Главного организационно-мобилизационного управления Генштаба ВС РФ Евгений Бурдинский объяснил желание "запасников" перейти на военную службу положительными изменениями в российских войсках.</description><rian:type xmlns:rian="http://rian.ru">article</rian:type><category>Безопасность</category><enclosure url="http://cdn5.img22.ria.ru/images/102532/27/1025322746.jpg" type="image/jpeg" length="27833"/></item>

And I have trouble parse image of RSS. How key I can use to import image? I don't understand, unfortunately.

This is my code, help that I parse RSS

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {

    element = elementName;

    if ([element isEqualToString:@"item"]) {

        item    = [[NSMutableDictionary alloc] init];
        title   = [[NSMutableString alloc] init];
        link    = [[NSMutableString alloc] init];
        pubDate = [[NSMutableString alloc] init];
    }

}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {

    if ([elementName isEqualToString:@"item"]) {

        [item setObject:title forKey:@"title"];
        [item setObject:link forKey:@"link"];
        [item setObject:pubDate forKey:@"pubDate"];

        [feeds addObject:[item copy]];

    }

}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {

    if ([element isEqualToString:@"title"]) {
        [title appendString:string];
    } else if ([element isEqualToString:@"link"]) {
        [link appendString:string];
    } else if ([element isEqualToString:@"pubDate"]) {
        [pubDate appendString:string];
    }

}

- (void)parserDidEndDocument:(NSXMLParser *)parser {

    [self.tableView reloadData];
    [self.refreshControl endRefreshing];
    NSLog(@"%@", feeds);

}

Upvotes: 0

Views: 216

Answers (1)

Imotep
Imotep

Reputation: 2056

I guess the image you want to download is the "enclosure" field in your XML.

In the didStartElement: method, use the attributeDict parameter to get the "url","type" and "length" parameters of your "enclosure" field. Once you have the URL, you can use a NSURLConnection object

Upvotes: 1

Related Questions