我正在使用Soap Web服务并获得XML响应,并且响应我存储在NSMutableData中,并且比我使用NSXMLParser执行XML解析更有用。我的问题是,有些时候它是有效的,有些时候我不能确定问题是什么,所以任何人都可以帮助我摆脱这个问题。 我使用这个代码 -Xml解析(WSDL格式)不能解析数据一些?
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];
}
和也越来越响应IN-
-(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方法不会调用。 这里怎么回事?请帮忙,并对任何英文错误感到抱歉。