I used RestKit to load XML data from a resource. That worked perfect, but now I want to change my whole program to read local XML files. I found the possibility to read a local xml file and parse it through RestKit in the Google RestKit Group:
NSString *string = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"testing" ofType:@"xml"] encoding:NSUTF8StringEncoding error:nil];
id<RKParser> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:RKMIMETypeXML];
id result = [parser objectFromString:string error:nil];
NSLog(@"%@",[[[[result objectForKey:@"sample"] objectForKey:@"nested"] objectForKey:@"tags" ] description]);
But now I want to load this object with my mapping. My old code with loading from a server:
RKObjectManager *objectManager = [RKObjectManager sharedManager];
RKURL *URL = [RKURL URLWithBaseURL:[objectManager baseURL] resourcePath:[xmlFile path] queryParameters:nil];
[objectManager.mappingProvider setMapping:myMapping forKeyPath:myKeyPath];
[objectManager loadObjectsAtResourcePath:[NSString stringWithFormat:@"%@", [URL resourcePath]] usingBlock:^(RKObjectLoader *loader) {
loader.delegate = self;
}];
After that I get my mapped objects in the didLoadObjects delegate of RestKit. How can I do the same for my local xml object?
I found the following solution for the problem. Works like a charm.