使用 touchXML 解析 `` RSS feed 标签

发布于 2024-09-07 04:19:31 字数 3102 浏览 3 评论 0原文

我有以下 RSS 提要,我正在尝试使用 iPhone 应用程序的 touchXML 对其进行解析。

<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>

我遇到的问题是我无法访问 标记,尤其是 处的 url。我使用以下方法来解析 rss feed 的代码。

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

我该如何获取存储在 中的网址?

谢谢

I have the following RSS feed that I'm trying to parse using touchXML for an iphone application.

<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&expires=1277743230&streamID=2678810&signature=beZ2o45XNredayqbtIzzL7khsnt1EEjwByf0yMgSEv8&size=20985109&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>

The problem I'm having is that I cannot access the <media:...> tags especially the url at <media:content>. The code I'm using the following method to parse the rss feed.

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

What can I do to get the url stored at the <media:content> ?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南风几经秋 2024-09-14 04:19:31

更改

resultNodes = [rssParsernodesForXPath:@"//item" 错误:nil];

to

resultNodes = [rssParsernodesForXPath:@"//*[local-name()='item']" error:nil];

change

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

to

resultNodes = [rssParser nodesForXPath:@"//*[local-name()='item']" error:nil];

许一世地老天荒 2024-09-14 04:19:31

使用 touchXML,您可以通过使用标签后面的部分来解析诸如 等标签。 <代码>:

media:title -> title

media:keywords -> keywords

Using touchXML you can parse tags like <media:content>, <media:group>, etc... by using the part of the tag that comes after the :

media:title -> title

media:keywords -> keywords
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文