2013-02-15 88 views
0

我有使用Sudzc(ARC分支)解析肥皂响应的问题。我有一些WCF服务为我们的应用程序存储数据。我设法连接到web服务,我可以成功地得到响应,但是当有一个响应带有z:ref属性时,我被卡住了。没有一个例子很难解释吗? ;)/我已经替换为例如“#someid”重要的数据,所以不要点,这是一个问题;)阅读复杂肥皂响应,ID和IDREFs节点与Sudzc [iOS]

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
<s:Header> 
    <ActivityId>#some credentials </ActivityId> 
</s:Header> 
<s:Body> 
    <GetMessagesResponse > 
     <GetMessagesResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> 
      <AllItemsCount>2</AllItemsCount> 
      <Items> 
       <Message z:Id="i1" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/"> 
        <GlobalId>#msgid</GlobalId> 
        <Content>bbbbbbbb</Content> 
        <CreatedDate>2013-02-14T16:33:07</CreatedDate> 
        <Priority>Normal</Priority> 
        <Receiver z:Id="i2"> 
         <GlobalId>#receiverid</GlobalId> 
         <CountryId>37</CountryId> 
         <CreationDate>2013-01-31T16:12:40</CreationDate> 
         <Gender>Male</Gender> 
         <IsDeleted>false</IsDeleted> 
         <Picture i:nil="true" /> 
         <UserName>tobiasz</UserName> 
        </Receiver> 
        <Sender z:Id="i3"> 
         <GlobalId>#senderid</GlobalId> 
         <CountryId>6</CountryId> 
         <CreationDate>2013-02-04T13:08:40</CreationDate> 
         <Gender>Male</Gender> 
         <IsDeleted>false</IsDeleted> 
         <Picture > 
          #"picture info" 
         </Picture> 
         <UserName>tobiasz2</UserName> 
        </Sender> 
        <Topic>RE: 56765765</Topic> 
       </Message> 
       <Message z:Id="i4" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/"> 
        <GlobalId>#msgid2</GlobalId> 
        <Content>aaaaaaa</Content> 
        <CreatedDate>2013-02-14T16:31:01</CreatedDate> 
        <Priority>High</Priority> 
        <Receiver z:Ref="i2"/> 
        <Sender z:Ref="i3"/> 
        <Topic>RE: 56765765</Topic> 
       </Message> 
      </Items> 
      <PageIndex>0</PageIndex> 
      <RetrievedDateTime>2013-02-15T13:14:57.0813487Z</RetrievedDateTime> 
     </GetMessagesResult> 
    </GetMessagesResponse> 
</s:Body> 

,你可以看到有标识接收机节点I2线 并且还可以看到另一个消息的节点来自相同的发送者和以同一接收器

sudzc生成的类用于解析该XML:

@interface ResultOfGetMessages : SoapObject{ 
    int _AllItemsCount; 
    NSMutableArray* _Items; 
    int _PageIndex; 
    NSDate* _RetrievedDateTime; 
} 

@interface Message : WSGlobalObject{ 
    NSString* _Content; 
    NSDate* _CreatedDate; 
    NSString* _Priority; 
    User* _Receiver; 
    User* _Sender; 
    NSString* _Topic; 
} 

@interface User : WSGlobalObject{ 
    int _CountryId; 
    NSDate* _CreationDate; 
    NSString* _Gender; 
    BOOL _IsDeleted; 
    PictureInfo* _Picture; 
    NSString* _UserName; 
} 
<ResultOfGetMessages> 
<AllItemsCount>2</AllItemsCount> 
<Items> 
    <Message> 
     <GlobalId>###</GlobalId> 
     <Content>bbbbbbbb</Content> 
     <CreatedDate>2013-02-14T16:33:07.000</CreatedDate> 
     <Priority>Normal</Priority> 
     <Receiver> 
      <GlobalId>####</GlobalId> 
      <CountryId>37</CountryId> 
      <CreationDate>2013-01-31T16:12:40.000</CreationDate> 
      <Gender>Male</Gender> 
      <IsDeleted>false</IsDeleted> 
      <Picture i:nil="true" ></Picture> 
      <UserName>tobiasz</UserName> 
      <Version>11</Version> 
     </Receiver> 
     <Sender> 
      <GlobalId>e4bda93c-a11c-4ae2-baf1-a15b00e918e7</GlobalId> 
      <CountryId>6</CountryId> 
      <CreationDate>2013-02-04T13:08:40.000</CreationDate> 
      <Gender>Male</Gender> 
      <IsDeleted>false</IsDeleted> 
      <Picture > 
       #### 
      </Picture> 
      <UserName>tobiasz2</UserName> 
      <Version>11</Version> 
     </Sender> 
     <Topic>RE: 56765765</Topic> 
    </Message> 
    <Message> 
     <GlobalId>###</GlobalId> 
     <Content>aaaaaaa</Content> 
     <CreatedDate>2013-02-14T16:31:01.000</CreatedDate> 
     <Priority>High</Priority> 
     <Receiver> 
      <CountryId>0</CountryId> 
      <IsDeleted>false</IsDeleted> 
     </Receiver> 
     <Sender> 
      <CountryId>0</CountryId> 
      <IsDeleted>false</IsDeleted> 
     </Sender> 
     <Topic>RE: 56765765</Topic> 
    </Message> 
</Items> 
<PageIndex>0</PageIndex> 

我认为问题奠定在反序列化的深度:Sudz与Touchxml无法读取(获得空接收器和发送器),为响应解析。解析器(if)试图使用指定的id来获取接收者节点,但它失败了,因为用此id标记的接收者节点在其他节点(前一个节点)中。

在此先感谢您的帮助和您的时间。

回答

0

我在使用soap.m编写序列化节点时遇到了类似的问题。不得不验证码:

// Deserializes the element in a dictionary. 
+(id)deserializeAsDictionary:(CXMLNode*)element { 

if([element childCount] == 1) { 
CXMLNode* child = [[element children] objectAtIndex:0]; 
if([child kind] == CXMLTextKind) 
{ 
    NSLog(@"The Child Node: %@", [[[element children] objectAtIndex:0] stringValue]); 
    return [[[element children] objectAtIndex:0] stringValue]; 

} 
} 

NSMutableDictionary* d = [NSMutableDictionary dictionary]; 
for(CXMLNode* child in [element children]) { 
id v = [Soap deserialize:child]; 
if(v == nil) { v = [NSNull null]; } 
[d setObject:v forKey:[child name]]; 
} 
return d; 
} 

到:

// Deserializes the element in a dictionary. 
+(id)deserializeAsDictionary:(CXMLNode*)element { 

if([element childCount] == 1) { 
CXMLNode* child = [[element children] objectAtIndex:0]; 
if([child kind] == CXMLTextKind) 
{ 
    NSLog(@"The Child Node: %@", [[[element children] objectAtIndex:0] stringValue]); 
    return [[[element children] objectAtIndex:0] stringValue]; 

} 
} 

NSMutableDictionary* d = [NSMutableDictionary dictionary]; 
for(CXMLNode* child in [element children]) { 
id v = [Soap deserialize:child]; 
if(v == nil) { v = [NSNull null]; } 
[d setObject:v forKey:[child name]]; 

if(check != nil) {    
NSInteger next = 1;    
key = [NSString stringWithFormat:@"%@%04d", [child name], next]; 
check = [d objectForKey:key]; 
while(check != nil) {     
    next++; 
    key = [NSString stringWithFormat:@"%@%04d", [child name], next]; 
    check = [d objectForKey:key]; 
} 
[d setObject:v forKey:key]; 
} else { 
[d setObject:v forKey:[child name]]; 
} 
+0

Tahnks答复。我想通过收集具有ID的节点来解决这个问题,并将其数据填充到空的节点并具有IDREF。从ID'ed节点收集的数据存储在数据库中。所以比你的解决方案有点复杂;) 我读过代码,它看起来很简单,很有希望。 现在我正在开发其他项目,我可能会在1月13日回到它,我要测试你的解决方案。再次感谢 ! – cbr 2013-11-29 12:40:15