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