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

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

问题描述:

我在我的应用程序中使用了SOAP webservice。我已将SOAP请求发送到服务器,并以XML格式获取resulst。我正在使用NSXML解析器来解析数据。在iPhone中使用NSXML解析器解析SOAP响应中的问题?

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

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

所以请帮助我。

+0

http://pastie.org/private/exl0v00mmqss1n5gxnpea – Pugal

+0

http://pastie.org/private/b430ecq5cwxbedhohy8y0w – Pugal

+0

http://pastie.org/private/pgi9tzmatbpocmfkkfviba – Pugal

试试这段代码。

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