【问题标题】:How to create dynamic soap envelop in objective c如何在目标 c 中创建动态肥皂包络
【发布时间】:2016-06-29 02:09:52
【问题描述】:

SOAP 正文

NSString *soapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
                                         "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance>\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema>\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/>\">\n"
                                         "<soap:Body>\n"
                                         " <Ins_VIP xmlns=\"http://tempuri.org/>\">\n"
                                         "<strVIPNo>%@</name>\n"
                                         "</name>\n"
                                         "</soap:Body>\n"
                                         "</soap:Envelope>\n" , str];

这是一个你知道的简单的肥皂消息。如果我想使用函数传递 str 的值,我如何构造它?

但是,我想为这个对象传值怎么可能?

【问题讨论】:

    标签: ios objective-c xml-parsing


    【解决方案1】:

    您可以这样做,您必须根据您的要求进行修改:

    //Add Request key and Values in below arrays
    NSArray* ReqKeyList;
    
    NSArray* ReqValueList;
    
    
        NSString *HeaderPart;
        NSString *BodyPart = @"";
        NSString *FooterPart;
        NSString *soapMessage;
    
    HeaderPart = [NSString stringWithFormat:@"<%@ xmlns=\"http://tempuri.org/\">\n",YourFunctionName];
    
    
    FooterPart = [NSString stringWithFormat:@"</%@>\n", YourFunctionName];
    
    for(int i=0;i<ReqKeyList.count;i++)
    {
    
       if (ReqValueList.count>i){
    
        BodyPart = [BodyPart stringByAppendingString:[NSString stringWithFormat:@"<%@>%@</%@>\n",ReqKeyList[i],ReqValueList[i],ReqKeyList[i]]];
    
       }
    
    }
    
    
    soapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
                       "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
                       "<soap:Body>\n"
                       "%@"
                       "%@"
                       "%@"
                       "</soap:Body>\n"
                       "</soap:Envelope>\n",HeaderPart,BodyPart,FooterPart];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多