Search code examples
iphoneobjective-cxmliosnsxml

Get the right node from duplicates xml with NSXML


I'm trying to us NSXML to parse a user's channel from youtube. Parsing works ok, but I can't seem to figure out how to get the link from any specific movie as their are 5 exact the same nodes as following:

<link rel="alternate" type="text/html" href="http://www.youtube.com/watch?v=vLleTDikufefbk&amp;feature=youtube_gdata" /> 
<link rel="http://gdata.youtube.com/schemas/2007#video.responses" type="application/atom+xml" href="http://gdata.youtube.com/feeds/api/videos/vLleTDikededubk/responses" /> 
<link rel="http://gdata.youtube.com/schemas/2007#video.related" type="application/atom+xml" href="http://gdata.youtube.com/feeds/api/videos/vLlededTDikubk/related" /> 
<link rel="http://gdata.youtube.com/schemas/2007#mobile" type="text/html" href="http://m.youtube.com/details?v=vLldedeeTDikubk" /> 
<link rel="self" type="application/atom+xml" href="http://gdata.youtube.com/feeds/api/users/node/uploads/vLlgrgreTDikubk" /> 

I've figured out how to get the attribute href from the node link. But since their are 5 different links I don't know how to only select the first one. Anyone got an idea?

Thnx you guys!!!


Solution

  • Found the solution already. I'll check if the link node has an attribute with alternate in it. If it does it has the right link node. Here is the code:

    NSMutableArray *link; if ([elementName isEqualToString:@"link"]) if (!link) link = [[NSMutableArray alloc] init]; NSString *alternate = [attributeDict objectForKey:@"rel"]; if([alternate isEqualToString:@"alternate"]){ NSString *href = [attributeDict objectForKey:@"href"]; alternate = NULL; }