【问题标题】:ios SOAP response is not in XML formatios SOAP 响应不是 XML 格式
【发布时间】:2013-10-08 05:23:08
【问题描述】:

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

谁能告诉我什么是问题,我该如何解决??

【问题讨论】:

    标签: ios xml parsing soap tbxml


    【解决方案1】:

    // 传递你的网址在这里

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

    【讨论】:

    • 感谢您的回复,但我们要求使用 TBXML 进行解析并使用 SOAP 消息进行请求...所以请您给我解决方案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多