简体   繁体   English

RSS feed XML和ATOM解析问题-GData-iPhone

[英]RSS feed XML & ATOM parse issue - GData - iPhone

I have a question regarding the parsing of an XLM document more precisely the ATOM format data. 我有一个关于XLM文档的解析,更确切地说是ATOM格式数据的问题。 (RSS feed). (RSS订阅)。

Here is an sample of the xlm document: 这是xlm文档的示例:

<item>
            <title>Panty + Stocking Print Preview</title>
            <link>http://SonicRocksMySocks.deviantart.com/art/Panty-Stocking-Print-Preview-200615179</link>
            <guid isPermaLink="true">http://SonicRocksMySocks.deviantart.com/art/Panty-Stocking-Print-Preview-200615179</guid>
            <pubDate>Fri, 11 Mar 2011 21:43:34 PST</pubDate>
            <media:title type="plain">Panty + Stocking Print Preview</media:title>

            <media:keywords></media:keywords>
            <media:rating>nonadult</media:rating>
            <media:category label="Movies &amp; TV">fanart/digital/drawings/movies</media:category>
            <media:credit role="author" scheme="urn:ebu">SonicRocksMySocks</media:credit>
            <media:credit role="author" scheme="urn:ebu">http://a.deviantart.net/avatars/s/o/sonicrocksmysocks.png?15</media:credit> 
            <media:copyright url="http://sonicrocksmysocks.deviantart.com">Copyright 2011 *SonicRocksMySocks</media:copyright>
            <media:thumbnail url="http://th00.deviantart.net/fs71/300W/i/2011/070/d/c/panty___stocking_print_preview_by_sonicrocksmysocks-d3bfvnv.png" height="351" width="300"/>

            <media:thumbnail url="http://th02.deviantart.net/fs71/150/i/2011/070/d/c/panty___stocking_print_preview_by_sonicrocksmysocks-d3bfvnv.png" height="150" width="128"/>
            <media:content url="http://th08.deviantart.net/fs71/PRE/i/2011/070/d/c/panty___stocking_print_preview_by_sonicrocksmysocks-d3bfvnv.png" height="967" width="826" medium="image"/>
            <media:content url="http://www.deviantart.com/download/200615179/" medium="document"/>
            <description><![CDATA[ The final version of this print will be available for sale at Sakura Con 2011. :3<br /><div><img src="http://th00.deviantart.net/fs71/300W/i/2011/070/d/c/panty___stocking_print_preview_by_sonicrocksmysocks-d3bfvnv.png" alt="thumbnail" /></div> ]]></description>
            <media:description type="html"><![CDATA[ The final version of this print will be available for sale at Sakura Con 2011. :3 ]]></media:description>
        </item>

This is how I parse the title, pubDate and link values: 这就是我解析标题,pubDate和链接值的方式:

 NSArray *channels = [rootElement elementsForName:@"channel"];
for (GDataXMLElement *channel in channels) 
{            

    NSString *blogTitle = [channel valueForChild:@"title"];                    

    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"];        
        NSDate *articleDate = [NSDate dateFromInternetDateTimeString:articleDateString formatHint:DateFormatHintRFC822];



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

    }      
}

I don't know how to retrieve the media:content line. 我不知道如何检索media:content行。 How can I do it? 我该怎么做? Can anyone help me with this? 谁能帮我这个?

Thank you a lot, Andrei 非常感谢Andrei

首先,通过这个简单的教程尝试使用NSXMLParsing

http://blancer.com/tutorials/i-phone/76999/parsing-xml-files/

您是否尝试遍历item的子item并在调试器或NSLog中检查它们?

I know which code you're using. 我知道您正在使用哪个代码。 It's actually very simple. 实际上非常简单。 You do it the same way you get the "title" and "link" and "pubDate". 您可以通过与获取“标题”,“链接”和“ pubDate”相同的方式进行操作。

 NSArray *channels = [rootElement elementsForName:@"channel"];
for (GDataXMLElement *channel in channels) 
{            

NSString *blogTitle = [channel valueForChild:@"title"];                    

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"];        
    NSDate *articleDate = [NSDate dateFromInternetDateTimeString:articleDateString formatHint:DateFormatHintRFC822];

    // Right here
    NSString *mediaCont = [item valueForChild:@"media:content"];



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

}      
}

After that you will need to alter your init method for RSSEntry to accept this new field. 之后,您将需要更改RSSEntry的init方法以接受此新字段。 You should try to look at the code that defines valueForChild, and see how it's using the GDataXML parser. 您应该尝试查看定义valueForChild的代码,并查看其如何使用GDataXML解析器。 Or you could use NSXML as suggested. 或者您可以按照建议使用NSXML。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM