2012-08-16 37 views
0

我有這樣的迴應:SudzC問題與SOAP關鍵字

<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> 

我在等待每一個對象被反序列化到NSDictionary中,因爲它適用於所有除上述一個其他WS響應。 與其他響應相比,在SOAP.m:+ (id) deserialize: (CXMLNode*) element方法中,語句NSString* type = [Soap getNodeValue:element withName:@"type"];的所有響應都返回nil,因此它將繼續返回[Soap deserializeAsDictionary:element];,並且我會得到必要的結果。 在我的情況下,當我達到NSString* type = [Soap getNodeValue:element withName:@"type"];時,該語句返回第一個對象的「NIVEAU」和另一個對象的「ZONE」,它不允許應用程序執行並執行[Soap deserializeAsDictionary:element];,並且我得到一個字符串對象而不是NSDictionary作爲解析結果。

你能幫我解決這個問題嗎?

+0

你是什麼意思「我得到格式化的字符串」?問題或問題不是很清楚,請您重新說明一下嗎?並且哪個不允許應用程序執行和執行部分也不清楚!你想要代碼最終做什麼? – doNotCheckMyBlog 2012-08-20 06:29:28

+0

我想要得到一個解決方案,當我的肥皂響應有一個字段名稱,這是一個SOAP關鍵字。 – 2012-08-20 06:37:43

+0

WSDL是由您製作還是您有任何控制權?我有類似的問題,我們結束添加命名空間到「類似的命名元素」[見:http://www.w3schools.com/xml/xml_namespaces.asp] – doNotCheckMyBlog 2012-08-20 06:40:04

回答

2

// Deserialize an object as a generic object 
+ (id) deserialize: (CXMLNode*) element{ 

    // Get the type 
    NSString* type = [Soap getNodeValue:element withName:@"type"]; 

展望[肥皂getNodeValue] ...我想通了,即使用這個功能是相當過於籠統。它用於獲取字段的屬性,作爲字段的值。

// 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; 
} 

在這照顧我創建了一個新的方法,這是越來越唯一的屬性值:

// 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; 
} 

和肥皂替代它:反序列化:

// 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) { 

而且它完全適用於我,直到現在。希望它能幫助有相同情況的其他人。