Iphone 使用NSXMLParser解析RSS时访问特定子元素

Iphone 使用NSXMLParser解析RSS时访问特定子元素,iphone,objective-c,rss,nsxmlparser,Iphone,Objective C,Rss,Nsxmlparser,亲爱的学者们: 我试图用以下item元素结构解析RSS提要 <item> <title>Title</title> <link>http://somelink.com</link> <description>The description</description> <author>rss@youtube.com</

亲爱的学者们: 我试图用以下item元素结构解析RSS提要

<item> 
         <title>Title</title> 
         <link>http://somelink.com</link> 
         <description>The description</description> 
         <author>rss@youtube.com</author> 
         <guid isPermaLink="false">http://youtube.com/?v=XBE4AX0Iuvw</guid> 
         <pubDate>Thu, 11 Nov 2010 10:56:44 +0000</pubDate> 
         <media:title>Media Title</media:title> 
         <media:thumbnail width="120" url="http://i1.ytimg.com/vi/XBE4AX0Iuvw/default.jpg" height="90"/> 
         <media:category label="Tags"/> 
         <media:player url="http://youtube.com/?v=XBE4AX0Iuvw"/> 
         <media:credit>Credit name</media:credit> 
         <enclosure url="http://youtube.com/v/XBE4AX0Iuvw.swf" duration="104" type="application/x-shockwave-flash"/> 
</item> 

这似乎是一个我不熟悉的语法问题,它抓住了存储在媒体中的值:thumbnail.url。有人能帮我怎么做吗?

因为
url
media:thumbnail
元素的一个属性,您需要通过
didStartElement:
中的
attributes
字典访问它。
foundCharacters:
消息(我假设是将文本累积到
workingPropertyString
)只针对元素的开始和结束标记之间的字符数据发送。

要轻松获取xml文件中的媒体:缩略图(或任何元素值),
使用xpath查询。为了执行XPathQuery,您可以使用libxml2

您的XPath查询听起来是这样的:
//media:thumbnail/@url

并将给您:
http://i1.ytimg.com/vi/XBE4AX0Iuvw/default.jpg

请阅读以下内容: (按照说明操作)

嗨,朋友们

 i have similiar issue of retriving image url from MediaThumbnail attr from my feed,
你们可以在didStartElement上写这篇文章,因为它检查媒体:thumnail内部url,在这里我们可以获取图像url字符串,它对我有用

  if ([elementName isEqualToString:kEntryStr])
{
    self.workingEntry = [[[AppRecord alloc] init] autorelease];
}
else if([elementName isEqualToString:@"media:thumbnail"]) {
NSMutableString *currentImgUrl = [[NSMutableString alloc] init];
    [currentImgUrl appendString:[attributeDict objectForKey:@"url"]];
    NSLog(@"url:%@",currentImgUrl);
    self.workingEntry.imageURLString = currentImgUrl;
}
storingCharacterData = [elementsToParse containsObject:elementName];
  if ([elementName isEqualToString:kEntryStr])
{
    self.workingEntry = [[[AppRecord alloc] init] autorelease];
}
else if([elementName isEqualToString:@"media:thumbnail"]) {
NSMutableString *currentImgUrl = [[NSMutableString alloc] init];
    [currentImgUrl appendString:[attributeDict objectForKey:@"url"]];
    NSLog(@"url:%@",currentImgUrl);
    self.workingEntry.imageURLString = currentImgUrl;
}
storingCharacterData = [elementsToParse containsObject:elementName];