简体   繁体   中英

RestKit and key-value coding … how to address repeating elements?

I've got a document that looks like this sometimes:

<doc>
  <titleInfo>
    <title>One version of the title</title>
  </titleInfo>
  <titleInfo>
    <title>Another version</title>
  </titleInfo>
</doc>

But other times it looks like this:

<doc>
  <titleInfo>
    <title>This is the only version of the title</title>
  </titleInfo>
</doc>

I'm trying to map this to an array in my object with the following:

[mapping mapKeyPath:@"titleInfo.title" toAttribute:@"titles"];

This works in the first case, but on the second case I receive

RKObjectMappingOperation.m:199 Failed transformation of value at keyPath 'titleInfo.title'. No strategy for transforming from '__NSCFString' to 'NSArray'

Clearly RestKit is correctly interpreting the first document as containing an array of strings -- but in the case of the second document, I can't find a way to force that same interpretation.

Is there a simple way to express this with the KVC facilities in RestKit, or am I better off writing some entirely custom mapper?

As per Blake Walters: The LibXML parser on master and in 0.9.3 has had numerous issues and was recently replaced with an NSXMLParser based solution in the development branch of RestKit and this solves some issues.

The better method is to wrap the repeating elements into an array for access.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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