开发者

UITable view,images,rssfeeds

开发者 https://www.devze.com 2023-02-17 00:45 出处:网络
i m using nsxmlparserto read the apple itunes rss feed..could u guys help to read this particular xml image.

i m using nsxmlparser to read the apple itunes rss feed..could u guys help to read this particular xml image.

<im:image height="55">http://a1.phobos.apple.com/us/r1000/028/Music/5c/aa/fe/mzi.fsnbyjmf.55x55-70.jpg</im:image>

below is the code

 - (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];
    }
}


@user652878 try this coding its works well..... In didStartelement, write as follows.. else if([elementName isEqualToString:@"media:content"])

{
    currentImage = [attributeDict valueForKey:@"url"];
}

In didEndElement, ....... else if([elementName isEqualToString:@"media:content"]){

              [item setObject:currentImage forKey:@"image"];
 }

In foundcharacters........................ else if([currentImage isEqualToString:@"media:content"]) {

    [currentImage appendString:string];
}

use NSLog to see that we get image link or not.... Sure u will get ur solution...

0

精彩评论

暂无评论...
验证码 换一张
取 消