我正在开发一个应用程序,我使用TBXML解析器消耗SOAP响应。 但我面临的问题是SOAP响应没有采用正确的XML格式。 以下是我收到的SOAP响应:
<?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><?xml version="1.0" encoding="UTF-8" standalone="no"?><Results><Row>&
lt;MESSAGE_TYPE>REQAPPRV</MESSAGE_TYPE><NOTIFICATION_CNT>2<
/NOTIFICATION_CNT><WORKFLOW_NAME>Purchase Requisition</WORKFLOW_NAME><
/Row><Row><MESSAGE_TYPE>POAPPRV</MESSAGE_TYPE><NOTIFICATION_CNT>4<
/NOTIFICATION_CNT><WORKFLOW_NAME>Purchase Order</WORKFLOW_NAME></Row><
/Results></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 :(得分:0)
//传递您的网址
首先使用NSXml解析器,您需要在.h中声明NSXmlParser委托。然后尝试这段代码
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);
}