I’ve been struggling for a while now trying to figure this out and I’m hoping someone out there can help.
I’m using the GData XML parser to read through the Atom feed provided by Youtube. I can access everything but elements that exist in a namespace eg:
Here is a code snippet that I’m attempting to make work:
NSArray *items = [rootElement elementsForName:@"entry"];
for (GDataXMLElement *item in items) {
NSDictionary *namespaces = [[NSDictionary alloc] initWithObjectsAndKeys:
@"media", @"http://search.yahoo.com/mrss/",
nil];
NSArray *thumbnails = [item nodesForXPath:@"media:thumbnail']" namespaces:namespaces error:0];
I’m certain I’m simply declaring the namespace incorrectly, but I can’t for the life of me figure out how to do it properly. Can anyone help? I’d prefer to solve this with XML rather then using the GData api to process youtube (seems overly complicated just to get a simple value in an RSS feed).
Thanks!
media:thumbnail is inside media:group; you need the full path to the elements being selected. Take a look at an XPath tutorial like this and don’t ignore the error responses from XPath.