0

我需要创建一个NSStringxml 格式的文件,以便将其作为 Web 服务请求发送。

我已经NSString使用此代码创建了结构化的 xml

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

     }
4

1 回答 1

0

您在生成的 xml 字符串中缺少一些标签。来自 Web 服务的任何 xml 响应都将如下所示。

您的 xml 必须嵌入在此..

<?xml version="1.0" encoding="utf-8"?>
<root>
//your generated xml with tags
</root>
于 2012-09-07T06:22:58.533 回答