【问题标题】:Parse youtube api feed v2解析 youtube api 提要 v2
【发布时间】:2012-07-17 02:19:44
【问题描述】:

我正在尝试解析 YouTube 数据 API 提供的 YouTube 供稿。此提要列出了所有视频uploaded by a specific user,例如:https://gdata.youtube.com/feeds/api/users/google/uploads?v=2

我在我的 iOS 应用程序中使用 touchXML。我尝试使用 CXMLDocument 中的 nodesForXPath 函数收集所有 <entry> 节点。

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)

但是这个查询没有返回任何东西。我检查了 xpath 语法;我觉得没有错。

【问题讨论】:

    标签: objective-c ios xml xpath touchxml


    【解决方案1】:

    我找到了问题所在。它是关于 Xpath 和命名空间的。为了使用 xpath 解析 XML 文档,我必须为我想要支持的每个命名空间创建一个默认映射。

    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];
    

    更多关于TouchXML的解释。 我发现了一篇关于 GDataXML 的帖子,它可能有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-02
      • 2012-10-19
      • 2011-03-10
      • 2013-03-27
      • 1970-01-01
      • 1970-01-01
      • 2011-11-30
      • 2011-04-30
      相关资源
      最近更新 更多