Xml解析(WSDL格式)有时不解析数据



我正在使用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方法调用有时不调用。这里出了什么问题?请帮忙,英语上的任何错误都很抱歉。

问题是我通过web服务获得HTML响应,所以xml处理器挂在上面。有时错误来自web服务端与HTML内容。

可能是连接(或)解析不成功。你可以通过如果(xmlparse解析){blahblahblah}其他的{人士同成功人士区分开来解析}

最新更新