如何使用 Attributes & 来解析 SAX?使用 iPhone SDK 获取 URL 路径的值?
我正在尝试使用 SAX 进行解析,并认为 iPhone 开发中心的 TopSongs 示例是一个不错的起点。我得到了大部分内容,但是当涉及到节点内的属性和值时,我在任何地方都找不到好的例子。 XML 具有封面艺术 URL 的路径。 XML 节点如下所示。
<itms:coverArt height="60" width="60">http://a1.phobos.apple.com/us/r1000/026/Music/aa/aa/27/mzi.pbxnbfvw.60x60-50.jpg</itms:coverArt>
我尝试过的是这个 startElement...
((prefix != NULL && !strncmp((const char *)prefix, kName_Itms, kLength_Itms)) &&
(!strncmp((const char *)localname, kName_CoverArt, kLength_Item) &&
!strncmp((const char *)attributes, kAttributeName_CoverArt, kAttributeLength_CoverArt) &&
!strncmp((const char *)attributes, kValueName_CoverArt, kValueLength_CoverArt) ||
!strncmp((const char *)localname, kName_Artist, kLength_Artist) ||
并再次拾取它,最后只使用本地名称,如下所示。
if (!strncmp((const char *)localname, kName_CoverArt, kLength_CoverArt)) { importer.currentSong.coverArt = [NSURL URLWithString:importer.currentString];
跟踪是 -[Song setCoverArt:]: 无法识别的选择器发送到实例。
I'm trying to get my head around parsing with SAX and thought a good place to start was the TopSongs example found at the iPhone Dev Center. I get most of it but when it comes to reaching Attributes and Values within a node I can't find a good example anywhere. The XML has a path to a URL for the coverArt. And the XML node looks like this.
<itms:coverArt height="60" width="60">http://a1.phobos.apple.com/us/r1000/026/Music/aa/aa/27/mzi.pbxnbfvw.60x60-50.jpg</itms:coverArt>
What I've tried is this for the startElement…
((prefix != NULL && !strncmp((const char *)prefix, kName_Itms, kLength_Itms)) &&
(!strncmp((const char *)localname, kName_CoverArt, kLength_Item) &&
!strncmp((const char *)attributes, kAttributeName_CoverArt, kAttributeLength_CoverArt) &&
!strncmp((const char *)attributes, kValueName_CoverArt, kValueLength_CoverArt) ||
!strncmp((const char *)localname, kName_Artist, kLength_Artist) ||
and picking it up again with just the localname at the end like this.
if (!strncmp((const char *)localname, kName_CoverArt, kLength_CoverArt)) { importer.currentSong.coverArt = [NSURL URLWithString:importer.currentString];
The trace is -[Song setCoverArt:]: unrecognized selector sent to instance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您还没有在
Song
类中合成coverArt
属性(使用@synthesize
关键字)。这就是创建-[Song setCoverArt:]
方法的原因,当您在currentSong
上设置coverArt
属性时,会调用该方法。Sounds like you haven't synthesized the
coverArt
property in yourSong
class (using the@synthesize
keyword). That's what creates the-[Song setCoverArt:]
method which is called when you set thecoverArt
property oncurrentSong
.