2013-10-08 83 views
0

我正在開發一個應用程序,使用TBXML分析器來消費SOAP響應。 但是我面臨的問題是SOAP響應沒有以正確的XML格式進入。 以下是SOAP響應,我接受:ios SOAP響應不是XML格式

<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.or 
/soap/envelope/"><S:Body><ns2:getNotificationCountResponse xmlns:ns2="http://wfnwebservice.oi.com 
/"><return>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;&lt;Results&gt;&lt;Row&gt;& 
lt;MESSAGE_TYPE&gt;REQAPPRV&lt;/MESSAGE_TYPE&gt;&lt;NOTIFICATION_CNT&gt;2&lt; 
/NOTIFICATION_CNT&gt;&lt;WORKFLOW_NAME&gt;Purchase Requisition&lt;/WORKFLOW_NAME&gt;&lt; 
/Row&gt;&lt;Row&gt;&lt;MESSAGE_TYPE&gt;POAPPRV&lt;/MESSAGE_TYPE&gt;&lt;NOTIFICATION_CNT&gt;4&lt; 
/NOTIFICATION_CNT&gt;&lt;WORKFLOW_NAME&gt;Purchase Order&lt;/WORKFLOW_NAME&gt;&lt;/Row&gt;&lt; 
/Results&gt;</return></ns2:getNotificationCountResponse></S:Body></S:Envelope> 

的SOAP請求消息如下,

NSString *soapMsg = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\ 
        <S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\" 
xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">\ 
        <SOAP-ENV:Header/>\ 
        <S:Body>\ 
        <ns2:getNotificationCount xmlns:ns2=\"http://wfnwebservice.oi.com/\">\ 
        <arg0>CBAKER</arg0>\ 
        </ns2:getNotificationCount>\ 
        </S:Body>\ 
        </S:Envelope>"]; 

任何一個可以請讓我知道什麼是一個問題,我怎麼能解決這個問題????

回答

0

//把您的網址在這裏

使用NSXML解析器首先需要聲明的NSXMLParser代表在.H。然後嘗試此代碼

NSString * urlString = [NSString stringWithFormat:@"http://www.webservicex.net/globalweather.asmx/GetCitiesByCountry?CountryName=%@",CountryName]; 

NSLog(@"%@",urlString); 

NSMutableURLRequest * req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]]; 

NSData * data = [NSURLConnection sendSynchronousRequest:req returningResponse:nil error:nil]; 

NSLog(@"%@",data); 

xmlResultString = [[NSMutableString alloc]init]; 

NSLog(@"%@",xmlResultString); 

parser = [[NSXMLParser alloc]initWithData:data]; 
[parser setDelegate:self]; 
[parser parse]; 

    // return result; 

} 

-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string 
{ 

    xmlDictionary=[[NSDictionary alloc]init]; 

    [xmlResultString appendString:[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]]; 

    NSLog(@"%@",xmlResultString); 

    xmlDictionary = [XMLReader dictionaryForXMLString:xmlResultString error:nil]; 

} 
-(void)parserDidEndDocument:(NSXMLParser *)parser 
{ 

    NSLog(@"%@",xmlDictionary); 

    NSArray * City=[[NSArray alloc]init]; 

    NSString* city =[[[xmlDictionary valueForKey:@"NewDataSet"] valueForKey:@"Table"] valueForKey:@"City"]; 

    NSLog(@"%@",city); 

    City=[[[xmlDictionary valueForKey:@"NewDataSet"] valueForKey:@"Table"] valueForKey:@"City"]; 

    NSLog(@"%@",City); 
} 



-(void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError 
{ 
    result = 0; 
    NSLog(@"%@",parseError); 

} 
NSString * urlString = [NSString stringWithFormat:@"http://www.webservicex.net/globalweather.asmx/GetCitiesByCountry?CountryName=%@",CountryName]; 

NSLog(@"%@",urlString); 

NSMutableURLRequest * req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]]; 

NSData * data = [NSURLConnection sendSynchronousRequest:req returningResponse:nil error:nil]; 

NSLog(@"%@",data); 

xmlResultString = [[NSMutableString alloc]init]; 

NSLog(@"%@",xmlResultString); 

parser = [[NSXMLParser alloc]initWithData:data]; 
[parser setDelegate:self]; 
[parser parse]; 

    // return result; 

} 

-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string 
{ 

    xmlDictionary=[[NSDictionary alloc]init]; 

    [xmlResultString appendString:[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]]; 

    NSLog(@"%@",xmlResultString); 

    xmlDictionary = [XMLReader dictionaryForXMLString:xmlResultString error:nil]; 

} 
-(void)parserDidEndDocument:(NSXMLParser *)parser 
{ 

    NSLog(@"%@",xmlDictionary); 

    NSArray * City=[[NSArray alloc]init]; 

    NSString* city =[[[xmlDictionary valueForKey:@"NewDataSet"] valueForKey:@"Table"] valueForKey:@"City"]; 

    NSLog(@"%@",city); 

    City=[[[xmlDictionary valueForKey:@"NewDataSet"] valueForKey:@"Table"] valueForKey:@"City"]; 

    NSLog(@"%@",City); 
} 



-(void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError 
{ 
    result = 0; 
    NSLog(@"%@",parseError); 

} 
+0

感謝您的迴應,但它是我們的要求,使用TBXML解析和SOAP消息的請求...所以你可以請給我解決方案 –