2012-08-26 56 views
0

處理XML數據(讀取XML數據並插入sqlite讀取數據....等)後,我想移動到下一個視圖。如何檢查是否結束xml解析

如何檢查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 ]; 

} 

回答

2

NSXMLParser同步解析器。只要[xmlParser parse]返回,解析完成。

0

由於您使用NSXMLParser並將委託設置爲self,因此您的類應該實現NSXMLParserDelegate方法,並且在完成所有操作時調用一個「 - parserDidEndDocument:」。

相關問題