【发布时间】: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