I am having an issue with a blog I am working on. The method I am using to parse is:
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"];
}
}
EDIT: XML LOOKS LIKE:
<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 … Road Trip
]]></description>
<content:encoded><![CDATA[<p>Part 1 of the series … 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>
This way I can get the title of the article from the Title tag within the XML. Most xmls I have parsed have included the mp3, either in the "guid" or "link" tag. However, the current feed I am working with, looks like this:
<enclosure url="http://treymorgan.podbean.com/mf/feed/bf8mvq/Accommoditions.mp3" length="29865594" type="audio/mpeg"/>
How can I pass the url from the enclosure into an NSString?
Something like [[item attributeForName: @"url"] stringValue]
should do it. Depending on the actual location of the enclosure
element in the XML tree, you might need to use another element instead of channel
of course.
Answer is
[[[[item elementsForName: @"enclosure"] lastObject] attributeForName: @"url"] stringValue]