私はRESTKitの可能性に基づいて販売されています。RESTKitを使用した深いXML構造の解析
残念ながら、私が見つけたすべての例は、JSONを解析して、比較的フラットなJSONを解析することを中心に展開しています。残念ながら、世界の現実は、たくさんのXMLがあり、多くは醜いということです。
特に、深くネストされたXML構造を解析する良い例はありません。
私は自分の失敗がキーパスを理解していると思うし、この質問に対する答えがこの問題に直面している他の人たちのための標準的な例になると思っています。
人為的な例を考えてみましょう。次のXMLを考えてみましょう:
<?xml version="1.0"?>
<old_lady fate="perhaps she'll die!">
<bird reason = "to catch the spider">
<spider reason="to catch the fly">
<fly reason="why oh why?" action="swallowed" name="Al"/>
<fly reason="why oh why?" action="swallowed" name="Bob"/>
<fly reason="why oh why?" action="swallowed" name="Cory"/>
<fly reason="why oh why?" action="swallowed" name="Dan"/>
<fly reason="why oh why?" action="swallowed" name="Edgar"/>
</spider>
</bird>
</old_lady>
のは、私はこのうちフライオブジェクトのリストを取得したいとしましょう:
@interface Fly : NSObject
@property (retain) NSString *reason;
@property (retain) NSString *action;
@property (retain) NSString *name;
@end
だから、私はこのような何かをしたいと思っていた:
[RKObjectManager objectManagerWithBaseURL:[NSURL
URLWithString:@"http://some.server.com"]];
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Fly class]];
[mapping mapKeyPath:@"reason" toAttribute:@"reason"];
[mapping mapKeyPath:@"action" toAttribute:@"action"];
[mapping mapKeyPath:@"name" toAttribute:@"name"];
[RKObjectManager.sharedManager.mappingProvider setMapping:mapping
forKeyPath:@"//old_lady/bird/spider/fly"];
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"/path/to/rhyme.xml"
delegate:self];
しかし、これは私を取得します。
Encountered errors during mapping: Could not find an object mapping for keyPath: ''
問題は私の '// old_lady/bird/spider/fly'キーパスだと確信していますが、後で解決策をモデル化するための類似の例は見つかりません。ハープ?
ありがとうございました。あなたは私の日を保存:) – slobodans