我正在解析一个看起来像这样的XML文件:
<partie numero="1">
<exercice numero="1" libelle="blabla"></exercice>
<exercice numero="2" libelle="anything"></exercice>
</partie>
我正在使用Rapture XML库,因此如GitHub所述,我将执行以下操作:
RXMLElement *rxmlPartie = [rxmlParties child:@"partie"];
NSArray *rxmlUnExercice = [rxmlPartie children:@"exercice"];
我可以使用此行从Partie正确打印“ numero”属性:
NSLog(@"Partie #%@",[rxmlPartie attribute:@"numero"] );
但是,当我尝试在NSArray上使用iterate方法时:
[rxmlPartie iterate:@"partie.exercice" usingBlock: ^(RXMLElement *exercice) {NSLog(@"Exercice: %@ (#%@)", [exercice attribute:@"libelle"], [exercice attribute:@"numero"]);}];
我收到警告,应用程序崩溃,说:
-[RXMLElement iterate:usingBlock:]: unrecognized selector sent to instance 0xc67f870
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '- [RXMLElement iterate:usingBlock:]: unrecognized selector sent to instance 0xc67f870'
我是否忘记导入某些东西,还是我以一种不好的方式实现了该方法?
如果我尝试使用iterateWithRootXPath,则会发生相同的错误...
谢谢你的帮助!!
最佳答案
因此,我发现了我的问题所在。
在执行此操作之前,我对解析Rapture XML一无所知...所以我坚持使用该文档(就像有人在学校里告诉我的那样:-))。但是问题是在文档中使用的方法,即“ iterate usingBlock”未在框架中定义。
而不是使用
[rxmlPartie iterate:@"partie.exercice" usingBlock: ^(RXMLElement *exercice) {NSLog(@"Exercice: %@ (#%@)", [exercice attribute:@"libelle"], [exercice attribute:@"numero"]);}];
我在用着
[rxmlPartie iterate:@"exercice" with: ^(RXMLElement *exercice) {NSLog(@"Exercice: %@ (#%@)", [exercice attribute:@"libelle"], [exercice attribute:@"numero"]);}];
在框架内定义良好!
这让我开心!