IOS - 使用 GData 解析 Youtube RSS - 命名空间问题
我已经努力了一段时间了,试图解决这个问题,我希望有人能提供帮助。
我正在使用 GData XML 解析器来读取 Youtube 提供的 Atom feed。我可以访问除命名空间中存在的元素之外的所有内容,例如:
这是我试图使其工作的代码片段:
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];
我确信我只是错误地声明了命名空间,但我一生都不能这样做弄清楚如何正确地做到这一点。有人可以帮忙吗?我更愿意使用 XML 来解决这个问题,而不是使用 GData api 来处理 youtube(仅仅在 RSS feed 中获取一个简单的值似乎过于复杂)。
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
媒体:缩略图位于媒体:组内;您需要所选元素的完整路径。查看像 this 这样的 XPath 教程,不要忽略错误响应来自 XPath。
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.