0

I'm trying to parse a YouTube feed provided by the YouTube data API. This feed lists all videos uploaded by a specific user, like this one: https://gdata.youtube.com/feeds/api/users/google/uploads?v=2

I'm using touchXML in my iOS app. I've tried to collect all <entry> nodes using nodesForXPath function in CXMLDocument.

NSURL *url = [NSURL URLWithString: newsFeedUrl];
CXMLDocument *feedParser = [[CXMLDocument alloc] initWithContentsOfURL:url options:0 error:nil];
NSArray *resultNodes = [feedParser nodesForXPath:@"//entry" error:nil];
NSLog(@"%@",resultNodes.count); // >>> return (null)

But this query doesn't return anything. I have checked the xpath syntax; I don't think it's wrong.

SetFreeByTruth
  • 819
  • 8
  • 23
Jim
  • 31
  • 2

1 Answers1

0

I've found the issue. It's about Xpath and namespaces. In order to parse the XML document with xpath i have to create a default mapping for each namespace i want to support.

NSDictionary * maps = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"http://www.w3.org/2005/Atom",@"http://search.yahoo.com/mrss/",@"http://a9.com/-/spec/opensearch/1.1/",@"http://schemas.google.com/g/2005",@"http://gdata.youtube.com/schemas/2007",@"W/\"C08MQXg-cSp7I2A9WhJRFEs.\"",nil] forKeys:[NSArray arrayWithObjects: @"ns",@"media",@"openSearch",@"gd",@"yt",@"etag",nil]];
NSArray *resultNodes = [feedParser nodesForXPath:@"//ns:entry" namespaceMappings:maps error:nil];

More explanations here for TouchXML. I have found a post about GDataXML it might be useful.

Community
  • 1
  • 1
Jim
  • 31
  • 2