以xml格式创建NSString作为对iphone sdk中的webserver的请求?

时间:2012-09-07 06:13:19

标签: iphone xml parsing sudzc

我需要以xml格式创建NSString,以便我需要将其作为Web服务请求发送。

我使用此代码

创建了xml结构NSString
 NSMutableString *res = [NSMutableString string];

 [res appendString:@"<question>"];
 [res appendFormat:@"<productid>%@</productid>", [array objectAtIndex:0]];
 [res appendFormat:@"<questionid>%@</questionid>", [array objectAtIndex:1]];
 [res appendFormat:@"<valueid>%@</valueid>", [array objectAtIndex:2]];
 [res appendFormat:@"<answerText>%@</answerText>", [array objectAtIndex:3]];
 [res appendFormat:@"</question>"];

但是,当我发送此请求(使用sudzc创建的Web服务代码)时,我遇到了一些错误

 Entity: line 1: parser error : Start tag expected, '<' not found
 Bad Request
 Error: The operation couldn’t be completed. (CXMLErrorDomain error 1.)

这是我的发送字符串

 NSString *send=[NSString stringWithString:@"<request><ProductName>ppr</ProductName><questionid>fff</questionid><answerText>%@</answerText></request>"];

创建字符串xml时应该替换所有标签?

这是我的要求,

 [service CreateRequest:self action:@selector(CreateRequestHandler:) Email:@"xxxx"  Password:@"anoopgopalan" Token:@"xxx" Request:send];


     - (void) CreateRequestHandler: (id) value {

          // Handle errors
            if([value isKindOfClass:[NSError class]]) {
            NSLog(@"%@", value);
            return;
       }  

          // Handle faults
            if([value isKindOfClass:[SoapFault class]]) {
           NSLog(@"%@", value);
           return;
     }              


                 // Do something with the MFLAPIError* result
             MFLAPIError* result = (MFLAPIError*)value;
                 NSLog(@"CreateRequest returned the value: %@", result);

     }

1 个答案:

答案 0 :(得分:0)

您在结果xml字符串中缺少某些标记..来自Web服务的任何xml响应都将如下所示。

您的xml必须嵌入此..

<?xml version="1.0" encoding="utf-8"?>
<root>
//your generated xml with tags
</root>