Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8212345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:43:30+00:00 2026-06-07T10:43:30+00:00

I’m trying to parse a SOAP response using RestKit. I’m able to successfully convert

  • 0

I’m trying to parse a SOAP response using RestKit. I’m able to successfully convert the SOAP XML response into objects if I define the mappings and relationships myself. But, I was wondering if it’s possible to use introspection (or something else) to automatically convert the SOAP XML response into an Objective-C object.

Sample XML:

<return>
    <userId xsi:type="xsd:int">1113050187</userId>
    <location xsi:type="ns1:Location">
       <city xsi:type="xsd:string">San Francisco</city>
       <state xsi:type="xsd:string">California</state>
    </location>
</return>

I would like to convert this XML into this object:

@interface Return : NSObject

@property (strong, nonatomic) NSInteger userId; // attribute
@property (strong, nonatomic) Location *location; // relation

@end

The closest thing I could come up with is using introspection on the Return class to get all properties and using something like this for each attribute:
[mapping addAttributeMapping:[RKObjectAttributeMapping mappingFromKeyPath:@”userId.text” toKeyPath:@”userId”]];

And for relations, I could again use introspection to find out all my class objects and use mapRelationship:withMapping: on each one

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T10:43:31+00:00Added an answer on June 7, 2026 at 10:43 am

    I ended up defining a method that recursively maps the properties to XML nodes if their names match. The naming convention and the data type of the property is important for this to work.

    I’ve tried my best to clean this up before I post it here, but let me know if you need any help.

    - (RKObjectMapping *)mapMe:(Class)class
    {
        RKObjectManager *objectManager = [RKObjectManager sharedManager];
        RKObjectMapping *mapping = [RKObjectMapping mappingForClass:class];
        id classType = objc_getClass([NSStringFromClass(class) UTF8String]);
        unsigned int outCount, i;
        objc_property_t *properties = class_copyPropertyList(classType, &outCount);
        for (i = 0; i < outCount; i++) {
            objc_property_t property = properties[i];
    //        fprintf(stdout, "%s\n", property_getName(property));
    
            const char *type = property_getAttributes(property);
            NSString *typeString = [NSString stringWithUTF8String:type];
            NSArray *attributes = [typeString componentsSeparatedByString:@","];
    //        NSLog(@"attributes = %@", attributes);
            NSString *typeAttribute = [attributes objectAtIndex:0];
    //        NSLog(@"typeAttribute = %@", typeAttribute);
            NSString *propertyType = [typeAttribute substringFromIndex:1];
    
            if ([propertyType hasPrefix:@"@"] && [propertyType length] > 1) {
                NSString * typeClassName = [propertyType substringWithRange:NSMakeRange(2, [propertyType length]-3)];  //turns @"NSDate" into NSDate
                Class typeClass = NSClassFromString(typeClassName);
                if (typeClass != nil && ![typeClassName hasPrefix:@"NS"]) {
    //            my custom class detected.
                    RKObjectMapping *subMapping = [self mapMe:typeClass forObjectManager:objectManager];
                    [mapping mapRelationship:[NSString stringWithUTF8String:property_getName(property)] withMapping:subMapping];
                    [objectManager.mappingProvider setMapping:subMapping forKeyPath:[NSString stringWithUTF8String:property_getName(property)]];
                } else {
                    [mapping addAttributeMapping:[RKObjectAttributeMapping mappingFromKeyPath:[NSString stringWithFormat:@"%@.text", [NSString stringWithUTF8String:property_getName(property)]] toKeyPath:[NSString stringWithUTF8String:property_getName(property)]]];
                }
            }
        }
        free(properties);
        return mapping;
    }
    

    And then to map it automatically call it as:

    [self mapMe:[Myclass class]];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.