0

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

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

4

1 回答 1

0

// 传递你的 url 就在这里

首先使用 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);

}
于 2013-10-08T05:31:07.047 回答