1

我想解析具有相同名称但不同值的孩子的 rss。在这种情况下,我想解析来自子名称“类别”的值。

这是RSS格式:

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

我做了这样的事情:

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"];
 }

在这段代码中,我只从子名称类别中获得了第一个值。我如何解析这个孩子的所有价值并在一行中显示?任何想法?

非常感谢

4

1 回答 1

0

您必须更多地研究GDataXML属性解析方法

以下链接可能对您有所帮助

用于解析 XML 和获取属性的示例代码

解析-xml-属性-使用-gdataxmldocument

在此处查看 GData 示例

于 2012-09-24T09:44:13.193 回答