2011-03-15 55 views
0

我使用nsxmlparser來閱讀蘋果iTunes的rss feed..could你們可以幫助閱讀這個特定的XML圖像。UITable查看,圖像,rssfeeds

<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

我覺得你有一些代碼,以NSXMLParserDelegate使用,但你不確定如何創建NSXMLParser並開始該過程? NSXMLParser * dp = [[NSXMLParser alloc] initWithContentsOfURL:dpUrl]; [dp解析]; 將做到這一點。 – NWCoder 2011-03-15 04:52:36

+0

這JST粘貼代碼香港專業教育學院的一部分......其作品good..the的事情是,當我試圖拉這個XML圖像內容... \t \t \t \t \t HTTP ://a1.phobos.apple.com/us/r1000/028/Music/5c/aa/fe/mzi.fsnbyjmf.55x55-70.jpg \t \t \t \t \t \t \t \t \t http://a1.phobos.apple.com/us/r1000/028/Music/5c/aa/fe/mzi.fsnbyjmf.60x60-50.jpg \t \t \t \t \t \t \t \t \t http://a1.phobos.apple.com/us/r1000/028/Music/5c/aa/fe/mzi.fsnbyjmf.170x170- 75.jpg所有三個已經得到了相同的標籤...即時得到所有三個圖像的URL ....我只想要一個 – kingston 2011-03-15 05:35:14

回答

0

@ user652878試試這個編碼它的作品以及.....在didStartelement,編寫如下..否則,如果([的ElementName isEqualToString:@「媒體:內容 「])

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

在didEndElement,.......否則如果([的ElementName isEqualToString:@」 媒體:內容「]){

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

在foundcharacters ........................否則如果([currentImage isEqualToString:@ 「媒體:內容」]) {

[currentImage appendString:string]; 
} 

使用的NSLog地看到,我們得到的圖片鏈接或不....當然U將得到解決烏爾...

+0

@chakradar:在蘋果的RSS博客有3圖像網址... \t \t \t \t \t http://a1.phobos.apple.com/us/r1000/028/Music/5c/aa/fe/mzi.fsnbyjmf.55x55-70.jpg \t \t \t \t \t \t \t \t \t http://a1.phobos.apple.com/us/r1000/028/Music/5c/aa/fe/mzi.fsnbyjmf.60x60-50。 JPG \t \t \t \t \t \t \t \t \t http://a1.phobos.apple.com/us/r1000/028/Music/5c/aa/fe/mzi .fsnbyjmf.170x170-75。jpg \t \t \t \t \t我使用了im:圖片標籤,並且我能夠拉出所有3個url,我想要一個url – kingston 2011-03-15 05:22:41