View Full Version : Parsing XML not getting the enclosure

Mar 13, 2012, 10:47 AM
I am trying to parse an xml of a podcast to be able to download or stream an mp3 that is in the xml. Here is part of the code for parsing it:
- (void)parseAtom:(GDataXMLElement *)rootElement entries:(NSMutableArray *)entries {

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

NSArray *items = [rootElement elementsForName:@"entry"];
for (GDataXMLElement *item in items) {

NSString *articleTitle = [item valueForChild:@"title"];
NSString *articleUrl = nil;
NSArray *links = [item elementsForName:@"guid"];
for(GDataXMLElement *link in links) {
NSString *rel = [[link attributeForName:@"rel"] stringValue];
NSString *type = [[link attributeForName:@"type"] stringValue];
if ([rel compare:@"alternate"] == NSOrderedSame &&
[type compare:@"text/html"] == NSOrderedSame) {
articleUrl = [[link attributeForName:@"href"] stringValue];

NSString *articleDateString = [item valueForChild:@"updated"];
NSDate *articleDate = [NSDate dateFromInternetDateTimeString:articleDateString formatHint:DateFormatHintRFC3339];

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



Here is one of the 'episodes' from the XML

<title>A Place At His Table</title>

<itunes:author>Dale Jenkins</itunes:author>
<dc:creator>Dale Jenkins</dc:creator>
<description>SUNDAY AM: Dale speaks of God's Grace while comparing our lives to that of David and Mephibosheth</description>
<content:encoded>SUNDAY AM: Dale speaks of God's Grace while comparing our lives to that of David and Mephibosheth</content:encoded>
<pubDate>Sun, 26 Feb 2012 11:16:03 -0500</pubDate>
<itunes:subtitle>A Place At His Table</itunes:subtitle>

<itunes:summary>SUNDAY AM: Dale speaks of God's Grace while comparing our lives to that of David and Mephibosheth</itunes:summary>
<itunes:keywords>church of christ, sermon, spring meadows</itunes:keywords>
<itunes:duration>00:30:15</itunes:duration><enclosure url="http://www.smcoc.net/content/audio/sermons/2012/2012_2_26_a_place_at_his_table.mp3" length="12706816" type="" />
The didSelectRow code:
if (_webViewController == nil) {
self.webViewController = [[[WebViewController alloc] initWithNibName:@"WebViewController" bundle:[NSBundle mainBundle]] autorelease];
RSSEntry *entry = [_allEntries objectAtIndex:indexPath.row];
_webViewController.entry = entry;
[self.navigationController pushViewController:_webViewController animated:YES];
However, the URL that gets parsed from all of this is:
This is under the <link> tag in the XML. Could someone help me get it properly pointed to either what is in the <enclosure> tag or the <guid> tag?