我是iPhone的新鮮開發者。 我正在處理簡單的xml解析演示。 我只想如何得到下面的XML代碼的圖像?如何從XML獲取圖像?
<item>
<title>Rain washes out England qualifier</title>
<description>England's World Cup qualifier against Poland is postponed because of a waterlogged pitch and is rescheduled for 16:00 BST on Wednesday.</description>
<link>http://www.bbc.co.uk/sport/0/football/19941036</link>
<guid isPermaLink="false">http://www.bbc.co.uk/sport/0/football/19941036</guid>
<pubDate>Tue, 16 Oct 2012 21:18:26 GMT</pubDate>
<media:thumbnail width="66" height="49" url="http://news.bbcimg.co.uk/media/images/63530000/jpg/_63530879_016250328-1.jpg"/>
<media:thumbnail width="144" height="81" url="http://news.bbcimg.co.uk/media/images/63529000/jpg/_63529179_016250328-1.jpg"/>
</item>
我該如何獲取圖像?
我已經使用以下代碼獲得標題或說明。
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if([elementName isEqualToString:className])
{
[items addObject:item];
[item release];
item = nil;
}
else
{
if([currentNodeContent length] != 0)
{
if([className isEqualToString:@"item"])
{
if([elementName isEqualToString:@"title"]|| [elementName isEqualToString:@"description"] || [elementName isEqualToString:@"url"])
{
[item setValue:currentNodeContent forKey:currentNodeName];
if ([elementName isEqualToString:@"media:thumbnail"])
{
[item setValue:currentNodeContent forKey:@"url"];
}
}
else
{
}
}
}
else
{
}
}
[currentNodeContent release];
currentNodeContent = nil;
[currentNodeName release];
currentNodeName = nil;
}
在此先感謝。
你有沒有得到的網址? –
NSData * imageData = [NSData dataWithContentsOfURL:[NSURL urlWithString:imageLink]]; UIImage * image = [UIImage imageWithData:imageData]; 將上面的代碼放在NSXMLParser中,對於URL元素 – kamleshwar
但是,如果圖像或圖像的長度很大(這不推薦),這會導致解析速度較慢。 – kamleshwar