ios SOAP响应不是XML格式

时间:2013-10-08 05:23:09

标签: ios xml parsing soap tbxml

我正在开发一个应用程序,我使用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>&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>"];

任何人都可以让我知道什么是问题,我该如何解决?????

1 个答案:

答案 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);

}