iPhone Extract URL from XML enclosure

Discussion in 'iOS Programming' started by newtoiphonesdk, Jul 14, 2012.

  1. newtoiphonesdk macrumors 6502a

    Jul 30, 2010
    I am working on getting the URL from the following inside an XML:

    		<title>Accomidations on Your Trip</title>
    		<enclosure url="http://treymorgan.podbean.com/mf/feed/bf8mvq/Accommoditions.mp3" length="29865594" type="audio/mpeg"/>
    I just need the URL of the mp3. I am using GDataXML and I know I need to use GDataXMLNode to get the attributeForName enclosure, but not sure how to do it. Right now I have:

    - (void)parseRss:(GDataXMLElement *)rootElement entries:(NSMutableArray *)entries {
        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"];            
                GDataXMLNode *nodes = [item attributeForName:@"enclosure"];
                NSLog(@"%@", nodes);
    The NSLog comes back as null for each entry...Any thoughts?
  2. chown33 macrumors 604

    Aug 9, 2009
    "enclosure" isn't an attribute name. It's an element name. The "enclosure" element has attributes (url, length, type), but "enclosure" is not an attribute itself. The "enclosure" element is also an empty-element, but this has no bearing on the problem or a solution.

    What are the values of articleTitle and articleUrl at each iteration?
    What is the expected output for the given XML input?

Share This Page