简体   繁体   English

RestKit将XML映射到核心数据

[英]RestKit mapping XML to Core Data

I working with it for two days... I want get remote xml then parse/map it to core data. 我用了两天时间...我想获取远程xml,然后解析/映射到核心数据。 I have read bunch of tutorials, so at this moment I can connect with local server (yyuupii!), get xml, but I have problem with mapping. 我已经阅读了很多教程,因此目前可以连接本地服务器(yyuupii!),获取xml,但是映射存在问题。 I get 我懂了

-[RKObjectLoader canParseMIMEType:] Unable to find parser for MIME Type 'application/xml' -[RKObjectLoader canParseMIMEType:]无法找到MIME类型'application / xml'的解析器

-[RKObjectLoader isResponseMappable] Encountered unexpected response with status code: 200 (MIME Type: application/xml -> URL: http:///list.xml -- http:/// -- http:/// -- http:///) 2012-10-24 14:13:12.201 Sierpien[4650:907] Error Domain=org.restkit.RestKit.ErrorDomain Code=4 "The operation couldn't be completed. (org.restkit.RestKit.ErrorDomain error 4.)" -[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代码= 4“操作无法完成。(org.restkit.RestKit.ErrorDomain错误4.)”

Could you gave me some advice I will be thankful. 你能给我一些建议吗,我会很感激。

My XML 我的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>

My Entity 我的实体

@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

My Implementation 我的实施

- (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];
}

Ok I throw away RKObjectManager, now I connect with RKClient, get xml with 好吧,我扔掉RKObjectManager,现在我与RKClient连接,使用

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

Then I parse Xml by GDataXML, fill Pack with that parsed data. 然后我通过GDataXML解析Xml,并用该解析数据填充Pack。 It works. 有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM