I need to stop the connection of the libxml parser at certain point.Can anyone suggest me how to do this.
This is the method I used to establish the connection.
- (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;
}
Actually I am getting the exception when I tap the back button when the loading of data is under process.
// 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.
}
Anyone's help will me much appreciated.
Thank you, Monish.
The xmlStopParser
-function, available in the libxml2 API, might be what you are looking for.
Specified in the docs as void xmlStopParser(xmlParserCtxtPtr context)
.
The documentation is available here: http://xmlsoft.org/html/libxml-parser.html#xmlStopParser
Also, Alex Deem has a good tip in this thread: Is it possible to stop a libxml parser while the process is running?
精彩评论