Search code examples
iphoneobjective-crssgdataxml

Parse RSS by GDataXML


I want to parse rss that have child with the same name but different value. In this case, i want to parse the value from child name 'category'.

Here's the RSS Format:

<item><title>HAC Algorithm by holiccorp</title>
<link>http://www.freelancer.com/projects/PHP-Javascript/HAC-Algorithm.html</link>
<description>Need someone good at javascript coding and HAC Algorithm.    I need someone   to create and analyze the code,script and logic.    More details will be given after discussion.    ASAP project. (Budget: &#36;30-&#36;250 USD, Jobs: Algorithm, HTML, Javascript, PHP, Website Testing)</description>
<pubDate>Sun, 23 Sep 2012 13:20:17 -0400</pubDate>
<guid isPermaLink="false">Freelancer.com_project_2509687</guid>
<category domain="http://www.freelancer.com/jobs/">Algorithm</category>
<category domain="http://www.freelancer.com/jobs/">HTML</category>
<category domain="http://www.freelancer.com/jobs/">Javascript</category>
<category domain="http://www.freelancer.com/jobs/">PHP</category>
<category domain="http://www.freelancer.com/jobs/">Website Testing</category>
<coop:keyword>Algorithm</coop:keyword>
<coop:keyword>HTML</coop:keyword>
<coop:keyword>Javascript</coop:keyword>
<coop:keyword>PHP</coop:keyword>
<coop:keyword>Website Testing</coop:keyword>
<coop:keyword>project 2509687</coop:keyword>
<coop:keyword>HAC Algorithm</coop:keyword>
</item>

I did something like this:

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

    NSString *blogTitle = [channel valueForChild:@"title"];                    
    NSLog(@"blogTitle %@",blogTitle);
    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"];
        NSString *articleDescription = [item valueForChild:@"description"];
        NSDate *articleDate = [NSDate dateFromInternetDateTimeString:articleDateString formatHint:DateFormatHintRFC822];
        NSDate *timeStamp = [NSDate date];
        NSString *category = [item valueForChild:@"category"];
 }

Fron this code, I got only first value from child name category. How do i parse all value from this child and show in one line? Any idea?

Many Thanks


Solution

  • You have to study more about GDataXML attribute parsing methods

    The below links may help you

    example-code-for-parsing-xml-and-get-attributes

    parsing-xml-attribute-using-gdataxmldocument

    see the GData example here