无法使用 TouchXML 获取名称中带有冒号的 XML 元素
我有以下代码:
NSString *subtitle = [[[node elementsForName:@"subtitle"] objectAtIndex:0] stringValue];
NSString *duration = [[[node elementsForName:@"itunes:duration"] objectAtIndex:0] stringValue];
第一行工作完美。但第二行不起作用。我认为它与名称空间有关,但我对这一切都很陌生,所以我将不胜感激任何指导。谢谢你!
事实证明,我可以使用 elementsForLocalName:URI:
正确读取元素。现在的问题是,由于我使用的是 TouchXML 库,该方法似乎没有映射到 CXMLElement
结构(请参阅 此处)。
所以现在的问题是:如何将 CXMLElement
转换为 NSXMLElement
以便我可以使用该方法?
I have the following code:
NSString *subtitle = [[[node elementsForName:@"subtitle"] objectAtIndex:0] stringValue];
NSString *duration = [[[node elementsForName:@"itunes:duration"] objectAtIndex:0] stringValue];
The first line works perfectly. The second line though won't work. I assume it has something to do with namespaces, but I'm pretty new to all of this so I would appreciate any guidance. Thank you!
It turns out that I can use the elementsForLocalName:URI:
to read the element correctly. Now the problem is that since I am using the TouchXML library, it doesn't seem like that method has been mapped over to the CXMLElement
structure (see here).
So the question now is: how can I convert a CXMLElement
to an NSXMLElement
so that I can use that method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“itunes”是命名空间标识符。它本身实际上没有任何意义,它只是将 URI 与相关元素链接起来。您似乎正在使用 iTunes RSS 扩展,该扩展位于
http://www.itunes.com/dtds/podcast-1.0.dtd
命名空间下。因此,对于命名空间元素,我认为(我不熟悉 Objective-C 或 NSXML :P)你想要使用
elementsForLocalName
相反:对于第二个问题的答案,请参阅下面的评论。
"itunes" is the namespace identifier. It doesn't actually have any significance on its own, it just links a URI with the element in question. It looks like you're using the iTunes RSS extensions, which live under the namespace
http://www.itunes.com/dtds/podcast-1.0.dtd
.So, for namespaced elements, I think (I'm not familiar with Objective-C or NSXML :P) you want to use
elementsForLocalName
instead:For the answer to the second question, see comments below.