RestKit将XML映射到核心数据

时间:2012-10-24 12:38:16

标签: ios xml-parsing restkit

我使用了两天...我想获取远程xml然后解析/映射到核心数据。我已经阅读了一堆教程,所以此时我可以连接本地服务器(yyuupii!),获取xml,但我有映射问题。我得到了

  

- [RKObjectLoader canParseMIMEType:]无法找到MIME类型'application / xml'的解析器

     

- [RKObjectLoader isResponseMappable]遇到状态代码为200的意外回复(MIME类型:application / xml - > URL:   http:///list.xml - http:/// -   http:/// - http:///)2012-10-24   14:13:12.201 Sierpien [4650:907]错误   Domain = org.restkit.RestKit.ErrorDomain Code = 4“操作无法执行   完成。 (org.restkit.RestKit.ErrorDomain错误4。)“

你能给我一些建议我会感激。

我的XML

<packs>
    <pack>
        <cover>cover.png</cover>
        <info>Jakis.adres.pl</info>
        <link>Opis</link>
        <name>wrzesień</name>
        <price>5.00</price>
    </pack>
    <pack>
        <cover>cover2.png</cover>
        <info>Jakis1.adres.pl</info>
        <link>Opis31</link>
        <name>wrzesień12</name>
        <price>15.00</price>
    </pack>
</packs>

我的实体

@interface Pack : NSManagedObject

@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSString * link;
@property (nonatomic, retain) NSString * price;
@property (nonatomic, retain) NSString * info;
@property (nonatomic, retain) NSString * cover;

@end

我的实施

- (id)initClient
{
    self = [super init];
    if (self) {
        RKObjectManager *client = [RKObjectManager objectManagerWithBaseURL:[RKURL URLWithString:@"http://10.1.1.5:8888/"]];
        NSLog(@"I am your RKObjectManager singleton : %@", [RKObjectManager sharedManager]);
        client.serializationMIMEType = RKMIMETypeXML;

        RKObjectMapping* listMapping = [RKObjectMapping mappingForClass:[Pack class]];
        [listMapping mapKeyPath:@"cover" toAttribute:@"cover"];
        [listMapping mapKeyPath:@"name" toAttribute:@"name"];
        [listMapping mapKeyPath:@"info" toAttribute:@"info"];
        [listMapping mapKeyPath:@"link" toAttribute:@"link"];
        [listMapping mapKeyPath:@"price" toAttribute:@"price"];

        [[RKObjectManager sharedManager].mappingProvider setMapping:listMapping forKeyPath:@"packs.pack"];
    }
    return self;
}

- (void)loadPacks {
    [[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"/list.xml" delegate:self];
}

1 个答案:

答案 0 :(得分:0)

好的,我扔掉了RKObjectManager,现在我用RKClient连接,用

获取xml

[[RKClient sharedClient] get:@"/list.xml" delegate:self];

然后我通过GDataXML解析Xml,用解析后的数据填充Pack。它有效。