2012-05-24 24 views
1

我解析它看起來像這樣的XML文件:RaptureXML迭代:usingBlock預警和防撞

<partie numero="1"> 
     <exercice numero="1" libelle="blabla"></exercice> 
     <exercice numero="2" libelle="anything"></exercice> 
</partie> 

我使用的狂喜XML庫,從而在GitHub上解釋,我執行以下操作:

RXMLElement *rxmlPartie = [rxmlParties child:@"partie"]; 
NSArray *rxmlUnExercice = [rxmlPartie children:@"exercice"]; 

我能正確地從partie這一行打印「NUMERO」屬性:

NSLog(@"Partie #%@",[rxmlPartie attribute:@"numero"]); 

但是當我嘗試使用伊特在我的NSArray率的方法:

[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同樣的錯誤發生...

感謝您的幫助!

回答

1

所以,我發現了什麼是我的問題。

在做這件事之前我並不知道與Rapture XML配對......所以我堅持使用文檔(正如有人在學校告訴我的:-))。但問題是在文檔中使用的方法,這個「迭代使用塊」沒有在框架中定義。

而不是使用

[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"]);}]; 

這是框架內明確定義!

它使我的一天!

+0

我找不到'[rxmlPartie迭代:@「exercice」:^(RXMLElement * exercice)'這個api。 – jianpx