iPhone Extract URL from XML enclosure

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

  1. newtoiphonesdk macrumors 6502a

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

    Code:
    <item>
    		<title>Accomidations on Your Trip</title>
    <link>http://treymorgan.podbean.com/2012/06/05/accomidations-on-your-trip/</link>
    		<enclosure url="http://treymorgan.podbean.com/mf/feed/bf8mvq/Accommoditions.mp3" length="29865594" type="audio/mpeg"/>
    				</item>
    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:

    Code:
    - (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

    Joined:
    Aug 9, 2009
    Location:
    Brobdingnag
    #2
    "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