RESTKit의 잠재력으로 판매되었습니다.RESTKit을 사용한 심층 XML 구조 구문 분석
불행히도, 필자가 찾은 모든 예제는 JSON을 구문 분석하고 비교적 평평한 JSON을 파싱하는 것에 초점을 맞 춥니 다. 불행히도 세계의 현실은 많은 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>
것은 이제 나는이 플라이 개체 목록에서 싶어한다고 가정 해 봅시다 : 다음 XML을 고려
@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