0

作業中のブログに問題があります。私が解析に使用している方法は次のとおりです。

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

編集:XMLは次のように見えます:

<item>
    <title>Your Direction Determines Your Destination</title>
    <link>http://treymorgan.podbean.com/2012/06/05/your-direction-determines-your-destination/</link>

    <comments>http://treymorgan.podbean.com/2012/06/05/your-direction-determines-your-destination/#comments</comments>
    <pubDate>Tue, 05 Jun 2012 17:57:07 +0000</pubDate>
    <dc:creator>treymorgan</dc:creator>

<category></category>
    <guid isPermaLink="false">http://treymorgan.podbean.com/2012/06/05/your-direction-determines-your-destination/</guid>
    <description><![CDATA[Part 1 of the series &#8230; Road Trip

]]></description>
        <content:encoded><![CDATA[<p>Part 1 of the series &#8230; Road Trip
</p>
]]></content:encoded>

        <wfw:commentRss>http://treymorgan.podbean.com/2012/06/05/your-direction-determines-your-destination/feed/</wfw:commentRss>
        <enclosure url="http://treymorgan.podbean.com/mf/feed/x52488/DirectionDeterminesyourDestination.mp3" length="32015229" type="audio/mpeg"/>
</item>

このようにして、XML内のTitleタグから記事のタイトルを取得できます。私が解析したほとんどのxmlには、「guid」または「link」タグのいずれかにmp3が含まれています。ただし、現在使用しているフィードは次のようになります。

<enclosure url="http://treymorgan.podbean.com/mf/feed/bf8mvq/Accommoditions.mp3" length="29865594" type="audio/mpeg"/>

エンクロージャーからNSStringにURLを渡すにはどうすればよいですか?

4

1 に答える 1

2

のような何か[[item attributeForName: @"url"] stringValue]がそれを行う必要があります。XML ツリー内の要素の実際の場所によっては、当然ではenclosureなく、別の要素を使用する必要がある場合があります。channel

答えは

[[[[item elementsForName: @"enclosure"] lastObject] attributeForName: @"url"] stringValue]
于 2012-07-14T20:44:07.723 に答える