【问题标题】:Xml Parsing (WSDL format) not parse the data some times?Xml Parsing(WSDL 格式)有时不解析数据?
【发布时间】:2012-01-09 10:09:37
【问题描述】:

我正在使用 Soap Web 服务并在 XML 中获取响应,并且我将响应存储在 NSMutableData 中,然后我使用 NSXMLParser 执行 XML 解析。我的问题是,有时它有效,有时无效,我无法确定是什么问题,所以任何人都可以帮助我解决这个问题。 我正在使用此代码-

    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
    [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [theRequest addValue: @"http://MYLINK......." forHTTPHeaderField:@"MY_action"];
    [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    if(theConnection)
    {
        webData_msg = [[NSMutableData data] retain];
    }

并得到响应-

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [webData_msg appendData:data];  
}

但是在得到响应后解析这里的xml-

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    if( xmlParser_msg)
    {
        [xmlParser_msg release];
        xmlParser_msg=nil;
    }
    xmlParser_msg = [[NSXMLParser alloc] initWithData: webData_msg];
    [xmlParser_msg setDelegate: self];
    [xmlParser_msg setShouldResolveExternalEntities: YES];
    [xmlParser_msg parse];

    [connection release];
    [webData_msg release];
}

这里出现问题,有时 NSXMLParserDelegate 方法调用有时不调用。 这里出了什么问题?请帮助并为英语中的任何错误表示歉意。

【问题讨论】:

    标签: iphone ios4 soap xml-parsing


    【解决方案1】:

    问题是我通过 Web 服务获得 HTML 响应,所以 xml 事务长挂在上面。 有时是来自带有 HTML 内容的 Web 服务端的错误。

    【讨论】:

      【解决方案2】:

      可能应该是连接(或)不成功的解析。您可以通过保留 如果(xmlParser 解析) { 等等等等等等 } 别的 { 解析失败 }

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-05-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-25
        • 1970-01-01
        相关资源
        最近更新 更多