ios - 如何在 objective-c 中创建动态 SOAP 信封

标签 ios objective-c xml-parsing

肥皂主体

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

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

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

最佳答案

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

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

关于ios - 如何在 objective-c 中创建动态 SOAP 信封,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35980742/

相关文章:

也处理 FeedBurner 的 Python RSS 解析器

objective-c - 在iPad上轻松制作动画帧图像

objective-c - 在选择时用自定义单元格替换标准 UITableViewCell

ios - 在ios中保持view controller的第一个状态

ios - 警告 : Attempt to present * whose view is not in the window hierarchy

iOS 7 视频未播放

iPhone 检测到用户向上移动了他们的设备

java - 简单的 XML 框架 - 奇怪的错误

ios - 如何将具体目录路径转换为 ​​NSURL?

c# - 高效解析大型 XML