iPhone 上使用 GData 解析 ATOM 数据

发布于 2024-10-21 10:28:01 字数 2390 浏览 5 评论 0原文

我正在尝试从 RSS 提要中解析 XML。

它包含 ATOM 数据,我想使用 GData 库解析它。

XML 代码如下所示:

<item>
    <title>Madoka Kaname</title>
    <link>http://emperpep.deviantart.com/art/Madoka-Kaname-200775806</link>
    <guid isPermaLink="true">http://emperpep.deviantart.com/art/Madoka-Kaname-200775806</guid>
    <pubDate>Sun, 13 Mar 2011 05:36:08 PDT</pubDate>
    <media:title type="plain">Madoka Kaname</media:title>

    <media:keywords></media:keywords>
    <media:rating>nonadult</media:rating>
    <media:category label="Paintings">manga/digital/paintings</media:category>
    <media:credit role="author" scheme="urn:ebu">emperpep</media:credit>
    <media:credit role="author" scheme="urn:ebu">http://a.deviantart.net/avatars/e/m/emperpep.jpg</media:credit> 
    <media:copyright url="http://emperpep.deviantart.com">Copyright 2011 *emperpep</media:copyright>
    <media:thumbnail url="http://th08.deviantart.net/fs70/300W/f/2011/072/a/9/madoka_kaname_by_emperpep-d3bjblq.jpg" height="389" width="300"/>

    <media:thumbnail url="http://th09.deviantart.net/fs70/150/f/2011/072/a/9/madoka_kaname_by_emperpep-d3bjblq.jpg" height="150" width="116"/>
    <media:content url="http://fc05.deviantart.net/fs70/f/2011/072/a/9/madoka_kaname_by_emperpep-d3bjblq.jpg" height="988" width="761" medium="image"/>
    <media:content url="http://www.deviantart.com/download/200775806/" medium="document"/>
    <description><![CDATA[ Digital Painting : Madoka KanamePicture of Madoka Kaname , made for an Anime convention.Tools:Sai 1.1.0 Photoshop CSWacom Intuos 3Macbook ProTime: 3 daysCharacters from Puella Magi Madoka Magica [...<br /><div><img src="http://th08.deviantart.net/fs70/300W/f/2011/072/a/9/madoka_kaname_by_emperpep-d3bjblq.jpg" alt="thumbnail" /></div> ]]></description>
    <media:description type="html"><![CDATA[ Digital Painting : Madoka KanamePicture of Madoka Kaname , made for an Anime convention.Tools:Sai 1.1.0 Photoshop CSWacom Intuos 3Macbook ProTime: 3 daysCharacters from Puella Magi Madoka Magica [... ]]></media:description>
</item>

我不知道如何获取 media:content 字段中包含的数据。谁能帮我解决这个问题吗?

I am trying to parse XML from an RSS feed.

It contains ATOM data and I would like to parse it using GData library.

The XML code looks like this:

<item>
    <title>Madoka Kaname</title>
    <link>http://emperpep.deviantart.com/art/Madoka-Kaname-200775806</link>
    <guid isPermaLink="true">http://emperpep.deviantart.com/art/Madoka-Kaname-200775806</guid>
    <pubDate>Sun, 13 Mar 2011 05:36:08 PDT</pubDate>
    <media:title type="plain">Madoka Kaname</media:title>

    <media:keywords></media:keywords>
    <media:rating>nonadult</media:rating>
    <media:category label="Paintings">manga/digital/paintings</media:category>
    <media:credit role="author" scheme="urn:ebu">emperpep</media:credit>
    <media:credit role="author" scheme="urn:ebu">http://a.deviantart.net/avatars/e/m/emperpep.jpg</media:credit> 
    <media:copyright url="http://emperpep.deviantart.com">Copyright 2011 *emperpep</media:copyright>
    <media:thumbnail url="http://th08.deviantart.net/fs70/300W/f/2011/072/a/9/madoka_kaname_by_emperpep-d3bjblq.jpg" height="389" width="300"/>

    <media:thumbnail url="http://th09.deviantart.net/fs70/150/f/2011/072/a/9/madoka_kaname_by_emperpep-d3bjblq.jpg" height="150" width="116"/>
    <media:content url="http://fc05.deviantart.net/fs70/f/2011/072/a/9/madoka_kaname_by_emperpep-d3bjblq.jpg" height="988" width="761" medium="image"/>
    <media:content url="http://www.deviantart.com/download/200775806/" medium="document"/>
    <description><![CDATA[ Digital Painting : Madoka KanamePicture of Madoka Kaname , made for an Anime convention.Tools:Sai 1.1.0 Photoshop CSWacom Intuos 3Macbook ProTime: 3 daysCharacters from Puella Magi Madoka Magica [...<br /><div><img src="http://th08.deviantart.net/fs70/300W/f/2011/072/a/9/madoka_kaname_by_emperpep-d3bjblq.jpg" alt="thumbnail" /></div> ]]></description>
    <media:description type="html"><![CDATA[ Digital Painting : Madoka KanamePicture of Madoka Kaname , made for an Anime convention.Tools:Sai 1.1.0 Photoshop CSWacom Intuos 3Macbook ProTime: 3 daysCharacters from Puella Magi Madoka Magica [... ]]></media:description>
</item>

I don't have any idea how to get the data contained in the media:content field. Can anyone help me with this one?

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

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

发布评论

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

评论(1

笑着哭最痛 2024-10-28 10:28:01

我找到了答案。这是代码:

NSArray *items = [channel elementsForName:@"item"];
    for (GDataXMLElement *item in items)
    {  
        NSString *articleTitle = [item valueForChild:@"title"];
        NSString *articleUrl = [item valueForChild:@"link"];            
        NSString *articleDateString = [item valueForChild:@"pubDate"]; 

        NSArray *mediaArray = [item elementsForName:@"media:content"]; //this is the code for what I needed
        for (GDataXMLElement *content in mediaArray)
        {
            NSString *url = [[content attributeForName:@"url"] stringValue];
            NSLog(@"URL: %@", url);
        }

        NSDate *articleDate = [NSDate dateFromInternetDateTimeString:articleDateString formatHint:DateFormatHintRFC822];

        RSSEntry *entry = [[[RSSEntry alloc] initWithBlogTitle:blogTitle 
                                                  articleTitle:articleTitle 
                                                    articleUrl:articleUrl 
                                                   articleDate:articleDate] autorelease];
        [entries addObject:entry];


    }

I found the answer. Here is the code:

NSArray *items = [channel elementsForName:@"item"];
    for (GDataXMLElement *item in items)
    {  
        NSString *articleTitle = [item valueForChild:@"title"];
        NSString *articleUrl = [item valueForChild:@"link"];            
        NSString *articleDateString = [item valueForChild:@"pubDate"]; 

        NSArray *mediaArray = [item elementsForName:@"media:content"]; //this is the code for what I needed
        for (GDataXMLElement *content in mediaArray)
        {
            NSString *url = [[content attributeForName:@"url"] stringValue];
            NSLog(@"URL: %@", url);
        }

        NSDate *articleDate = [NSDate dateFromInternetDateTimeString:articleDateString formatHint:DateFormatHintRFC822];

        RSSEntry *entry = [[[RSSEntry alloc] initWithBlogTitle:blogTitle 
                                                  articleTitle:articleTitle 
                                                    articleUrl:articleUrl 
                                                   articleDate:articleDate] autorelease];
        [entries addObject:entry];


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