处理完XML数据(读取xml数据并插入sqlite读取数据等)之后,我想转到下一个视图。
如何检查是否已完成解析XML?
我附上我的代码。我在哪里可以检查解析是否已完成?
-(IBAction)clickServerSync:(id)sender
{
if ([util checkNetwork]) {
[self LoadXml:@"LANG"];
[self LoadXml:@"CATEGORY"];
[self LoadXml:@"LIST"];
[self LoadXml:@"FILE"];
}
}
-(void)LoadXml:(NSString*)P_VAL
{
[indicator setHidden:NO];
NSString *smsURL = [NSString stringWithFormat:@"%@%@.asp", XML_URL, P_VAL];
NSString *sendAuthInfo = [NSString stringWithFormat:@"xx=%d" , 0 ];
NSString *val = [sendAuthInfo stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:smsURL]]autorelease];
[request setURL:[NSURL URLWithString:smsURL]];
[request setHTTPMethod:@"POST"];
[request setHTTPBody: [val dataUsingEncoding:NSUTF8StringEncoding]];
[self startAsyncLoad:request tag:P_VAL];
}
- (void)startAsyncLoad:(NSMutableURLRequest*)request tag:(NSString*)tag {
CustomURLConnection *connection = [[CustomURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES tag:tag];
if (connection) {
[receivedData setObject:[[NSMutableData data] retain] forKey:connection.tag];
}
}
- (NSMutableData*)dataForConnection:(CustomURLConnection*)connection {
NSMutableData *data = [receivedData objectForKey:connection.tag];
return data;
}
-(void)check_xmlParserEnd
{
[indicator setHidden:YES];
}
- (void)connection:(CustomURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSMutableData *dataForConnection = [self dataForConnection:(CustomURLConnection*)connection];
[dataForConnection setLength:0];
}
- (void)connection:(CustomURLConnection *)connection didReceiveData:(NSData *)data {
NSMutableData *dataForConnection = [self dataForConnection:(CustomURLConnection*)connection];
[dataForConnection appendData:data];
}
-(void)connectionDidFinishLoading:(CustomURLConnection*)connection
{
NSMutableData *dataForConnection = [self dataForConnection:(CustomURLConnection*)connection];
[connection release];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSXMLParser *xmlParser = [[[NSXMLParser alloc] initWithData:dataForConnection] autorelease];
XMLParser *parser = [[XMLParser alloc] initXMLParser];
[xmlParser setDelegate:(id)parser];
parser.viewDelegate = (id)self;
[xmlParser parse ];
}
答案 0 :(得分:2)
NSXMLParser
是同步解析器。只要[xmlParser parse]
返回,解析就完成了。
答案 1 :(得分:0)
由于您使用NSXMLParser并将委托设置为self,因此您的类应实现NSXMLParserDelegate方法,并在完成所有方法时调用“ - parserDidEndDocument:”。