2012-11-28 106 views
0

我在我的應用程序中使用了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

回答

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