2010-06-21 47 views
1

我需要在某个点停止libxml解析器的连接。任何人都可以告诉我如何做到这一点。如何在iphone sdk中的某个点停止libxml解析器中的连接?

这是我用来建立连接的方法。

- (BOOL)parseWithLibXML2Parser 
{ 
BOOL success = NO; 
ZohoAppDelegate *appDelegate = (ZohoAppDelegate*) [ [UIApplication sharedApplication] delegate]; 
NSString* curl; 
if ([self.lateFeeName length] == 0) 
{ 
    curl = @"https://invoice.zoho.com/api/view/settings/latefees?ticket="; 
    curl = [curl stringByAppendingString:appDelegate.ticket]; 
    curl = [curl stringByAppendingString:@"&apikey=bfc9c6dde7c889a19f8deea9d75345cd"]; 
    curl = [curl stringByReplacingOccurrencesOfString:@"\n" withString:@""]; 
} 

NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:curl]]; 

NSLog(@"the request parserWithLibXml2Parser %@",theRequest); 
NSURLConnection *con = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 

self.connection = con; 
[con release]; 
// This creates a context for "push" parsing in which chunks of data that are 
// not "well balanced" can be passed to the context for streaming parsing. 
// The handler structure defined above will be used for all the parsing. The 
// second argument, self, will be passed as user data to each of the SAX 
// handlers. The last three arguments are left blank to avoid creating a tree 
// in memory. 
_xmlParserContext = xmlCreatePushParserCtxt(&simpleSAXHandlerStruct, self, NULL, 0, NULL); 
if(self.connection != nil) 
{ 
    do 
    { 
     [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; 
    } while (!_done && !self.error); 
} 
if(self.error) 
{ 
    [self.delegate parser:self encounteredError:nil]; 
} else 
{ 
    success = YES; 
} 
return success; 
} 

实际上,当我在加载数据时正在点击后退按钮时,我正在收到异常。

// Called when a chunk of data has been downloaded. 
- (void)connection:(NSURLConnection *)connection 
didReceiveData:(NSData *)data 
{ 
// Process the downloaded chunk of data. 
xmlParseChunk(_xmlParserContext, (const char *)[data bytes], [data length], 0);//....Getting Exception at this line. 
} 

任何人的帮助,我将不胜感激。

谢谢, Monish。

回答