在iPhone中使用NSXML解析器解析SOAP响应中的问题?

时间:2012-11-28 12:39:59

标签: iphone soap nsxmlparser

我在我的应用中使用了SOAP webservice。我已经将SOAP请求发送到服务器并以XML格式获取结果。我正在使用NSXML Parser来解析数据。

我想获取数据“true”,当我试图解析内容应用程序崩溃时,我无法解析该数据。

<ServiceFinalResult>
<Response  xmlns="http://aaaa.com/test/schemas/services/myaccounts/data/_1_0">
  true
</Response> 
</ServiceFinalResult>

所以请帮帮我。

1 个答案:

答案 0 :(得分:0)

试试这段代码。

NSString *soapMessage = @"<?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"
    "<name>testName</name>\n"
    "</soap:Body>\n"
    "</soap:Envelope>\n";

NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:webServiceUrl];

NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];              
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req addValue:yourSoapAction forHTTPHeaderField:@"SOAPAction"];
[req addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"POST"];    
[req setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

NSHTTPURLResponse* urlResponse = nil;
NSError *error = [[[NSError alloc] init] autorelease];  
NSData *webData = [NSURLConnection sendSynchronousRequest:req returningResponse:&urlResponse error:&error];