Search code examples
iphoneiossoapsudzc

SudzC issue with SOAP keywords


I have this response:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <ns2:SurfaceElementListResponse xmlns:ns2="http://isiows.isiom.fr/schema/DmdCreation" xmlns:ns3="http://isiows.isiom.fr/schema/Error" xmlns:ns4="http://isiows.isiom.fr/schema/DmdDetail">
         <SurfaceElementListResult>
            <idSurfaceElement>9482</idSurfaceElement>
            <name>R04-</name>
            <type>NIVEAU</type>
         </SurfaceElementListResult>
         <SurfaceElementListResult>
            <idSurfaceElement>9486</idSurfaceElement>
            <name>Zone A</name>
            <type>ZONE</type>
         </SurfaceElementListResult>
      </ns2:SurfaceElementListResponse>
   </soap:Body>
</soap:Envelope>

I am waiting each object to be deserialized to NSDictionary, as it works on all the other WS response except one above. In comparison with other responses, in SOAP.m:+ (id) deserialize: (CXMLNode*) element method, all the responses for the statement NSString* type = [Soap getNodeValue:element withName:@"type"]; return nil, so it is continues with return [Soap deserializeAsDictionary:element]; and I get the necessary result. In my case when I reach to NSString* type = [Soap getNodeValue:element withName:@"type"]; the statement returns "NIVEAU" for the first object and "ZONE" for the other object, which does not allow the application go and execute [Soap deserializeAsDictionary:element]; and I get a string object instead of NSDictionary as parse result.

Could you please help me solving this issue?


Solution

  • In

    // Deserialize an object as a generic object
    + (id) deserialize: (CXMLNode*) element{
    
        // Get the type
        NSString* type = [Soap getNodeValue:element withName:@"type"];
    

    looking into the [Soap getNodeValue]... I figured out, that the use of this function is rather too general. It is used as for getting the attributes of the field, as the values of the fields.

    // Gets the value of a named node from a parent node.
    
    + (NSString*) getNodeValue: (CXMLNode*) node withName: (NSString*) name {
    
        // Set up the variables
        if(node == nil || name == nil) { return nil; }
        CXMLNode* child = nil;
    
        // If it's an attribute get it
        if([node isKindOfClass: [CXMLElement class]])
        {
            child = [(CXMLElement*)node attributeForName: name];
            if(child != nil) {
                return [child stringValue];
            }
        }
    
        // Otherwise get the first element
        child = [Soap getNode: node withName: name];
        if(child != nil) {
            return [child stringValue];
        }
        return nil;
    }
    

    In this care I created a new method which is getting only the attribute value:

    // Gets the value of a node attribute
    + (NSString*) getNodeAttributeValue: (CXMLNode*) node withName: (NSString*) name{
        // Set up the variables
        if(node == nil || name == nil) { return nil; }
        CXMLNode* child = nil;
    
        // If it's an attribute get it
        if([node isKindOfClass: [CXMLElement class]])
        {
            child = [(CXMLElement*)node attributeForName: name];
            if(child != nil) {
                return [child stringValue];
            }
        }
        return nil;
    }
    

    and replaced it in Soap:deserialize:

    // Deserialize an object as a generic object
    + (id) deserialize: (CXMLNode*) element{
    
        // Get the type
        NSString* type = [Soap getNodeAttributeValue:element withName:@"type"];
    //  NSString* type = [Soap getNodeValue:element withName:@"type"];
        if(type == nil || type.length == 0) {
    

    And it works perfectly for me, till now. Hope it will help others with the same situation.