我使用nsxmlparser来读取苹果itunes rss feed ..你们可以帮忙阅读这个特殊的xml图像。
<im:image height="55">http://a1.phobos.apple.com/us/r1000/028/Music/5c/aa/fe/mzi.fsnbyjmf.55x55-70.jpg</im:image>
下面是代码
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary*) attributeDict
{
currentElement = [elementName copy];
if ([elementName isEqualToString:@"entry"]) {
// clear out our story item caches...
item = [[NSMutableDictionary alloc] init];
currentTitle = [[NSMutableString alloc] init];
currentDate = [[NSMutableString alloc] init];
currentSummary = [[NSMutableString alloc] init];
currentLink = [[NSMutableString alloc] init];
currentString=[[NSMutableString alloc] init];
currentImage = [[NSMutableString alloc] init];
currentContent=[[NSMutableString alloc]init];
}
if ([attributeDict objectForKey:@"href"])
{
currentString=[attributeDict objectForKey:@"href"];
NSLog(@"what is my current string:%@",currentString);
[item setObject:currentString forKey:@"href"];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"entry"]) {
[item setObject:currentTitle forKey:@"title"];
[item setObject:currentLink forKey:@"link"];
[item setObject:currentSummary forKey:@"description"];
[item setObject:currentDate forKey:@"published"];
//[item setObject:currentImage forKey:@"im:image height=55"];
NSLog(@"the current image content:%@",item);
[stories addObject:[item copy]];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
//NSLog(@"found characters: %@", string);
// save the characters for the current item...///////////element
if ([currentElement isEqualToString:@"title"]) {
[currentTitle appendString:string];
} else if ([currentElement isEqualToString:@"link"]) {
[currentLink appendString:string];
} else if ([currentElement isEqualToString:@"description"]) {
[currentSummary appendString:string];
} else if ([currentElement isEqualToString:@"published"]) {
[currentDate appendString:string];
}
else if ([currentElement isEqualToString:@"url"]) {
[currentContent appendString:string];
}
}
答案 0 :(得分:0)
@ user652878试试这个编码很好用.....在didStartelement中,写如下.. else if([elementName isEqualToString:@“media:content”])
{
currentImage = [attributeDict valueForKey:@"url"];
}
在didEndElement中,....... else if([elementName isEqualToString:@“media:content”]){
[item setObject:currentImage forKey:@"image"];
}
在foundcharacters ........................ else if([currentImage isEqualToString:@“media:content”]) {
[currentImage appendString:string];
}
使用NSLog来查看我们是否获得图像链接....当然,你会得到你的解决方案......