2010-06-28 68 views
1

我有以下RSS提要,我试图使用touchXML解析iphone应用程序。使用touchXML解析`<media:content>`RSS提要标签

<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:ext="http://ooyala.com/syndication/ext/" xmlns:mediasl="http://www.slide.com/funspace/developer/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:boxee="http://boxee.tv/spec/rss/"> 
<channel> 
    <title>Channel Title</title> 
    <description>Channel Description</description> 
    <link>link</link> 
    <item> 
     <title>title</title> 
     <guid isPermaLink="false">k2dDRpMTpto4kdpU_NhGmNGKRK0Ny0PH</guid> 
     <pubDate>Fri, 25 Jun 2010 06:53:48 +0000</pubDate> 
     <media:title>title</media:title> 
     <media:keywords>Others</media:keywords> 
     <media:category scheme="http://www.ooyala.com">/JBay10</media:category> 
     <media:category scheme="http://www.ooyala.com">/JBay10/Webisodes</media:category> 
     <media:thumbnail url="http://ak.c.ooyala.com/k2dDRpMTpto4kdpU_NhGmNGKRK0Ny0PH/BqcWmm1bH0zjWgL35lMDoxOjBrO7OBB8" width="640" height="360"/> 
     <dcterms:valid>start=2010-06-25T06:53+00:00;scheme=W3C-DTF</dcterms:valid> 
     <media:group> 
      <media:content url="http://api.ooyala.com/syndication/stream_redirect?pcode=N2d2U6Azh1SxAcZeoJia-srBQAtY&amp;expires=1277743230&amp;streamID=2678810&amp;signature=beZ2o45XNredayqbtIzzL7khsnt1EEjwByf0yMgSEv8&amp;size=20985109&amp;length=163280" type="video/mp4" medium="video" expression="full" bitrate="900" framerate="25.0" samplingrate="32.0" duration="163" lang="en"/> 
     </media:group> 
    </item> 
    ... 
</channel> 

我遇到的问题是,我不能在<media:content>访问<media:...>标签特别的URL。我正在使用以下方法解析rss提要的代码。

-(NSMutableArray *) grabXMLFeed:(NSString *)feedAddress{ 

    NSURL *url = [NSURL URLWithString: feedAddress]; 

    CXMLDocument *rssParser = [[[CXMLDocument alloc] initWithContentsOfURL:url options:0 error:nil] autorelease]; 
    NSArray *resultNodes = NULL; 

    resultNodes = [rssParser nodesForXPath:@"//item" error:nil]; 
    NSMutableArray *videos = [[NSMutableArray alloc] init]; 

    for (CXMLElement *resultElement in resultNodes) { 

     int counter; 

     NSMutableDictionary *video = [[NSMutableDictionary alloc] init]; 

     for(counter = 0; counter < [resultElement childCount]; counter++) { 

      NSString *val = [[resultElement childAtIndex:counter] stringValue]; 

      if ([val length] != 0) { 
       [video setObject:[[resultElement childAtIndex:counter] stringValue] forKey:[[resultElement childAtIndex:counter] name]]; 
      }    
     } 

     [videos addObject:[video copy]]; 
     [video release]; 
    } 

    return videos; 
} 

我能做些什么来获取存储在<media:content>的url?

感谢

+0

嗨;)这是一个名称空间数据。我不确定,但是在TouchXML的google代码页上,他们提到了命名空间支持的路线图:http://code.google.com/p/touchcode/wiki/TouchXML – rogeriopvl 2010-06-28 17:29:02

+0

为什么不使用NSXMLParser? – Warrior 2010-06-28 17:58:05

+0

好吧,我会那样做的。 – ametade 2010-06-29 10:44:46

回答

3

使用touchXML可以解析标签,如<media:content><media:group>,等...通过使用:

media:title -> title 

media:keywords -> keywords 
4

变化后到来的标签的一部分

resultNodes = [rssParser nodesForXPath:@“// item”error:nil];

resultNodes = [rssParser nodesForXPath:@ “// * [本地名称()= '项目']” 错误:无];

+0

如何解析来自此解析器的XSD架构SOAP XML,因为它返回null – user366584 2012-01-03 10:14:50