IOS - 使用 GData 解析 Youtube RSS - 命名空间问题

发布于 2024-11-17 22:42:12 字数 706 浏览 2 评论 0原文

我已经努力了一段时间了,试图解决这个问题,我希望有人能提供帮助。

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

染墨丶若流云 2024-11-24 22:42:12

媒体:缩略图位于媒体:组内;您需要所选元素的完整路径。查看像 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文