Как остановить соединение в анализаторе libxml в какой-то момент в iphone SDK? - PullRequest
1 голос
/ 21 июня 2010

Мне нужно в какой-то момент прекратить соединение с анализатором 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.
}

Любая помощь будет мне очень признательна.

Спасибо, Мониш.

1 Ответ

2 голосов
/ 09 февраля 2011

Функция xmlStopParser, доступная в libxml2 API, может быть тем, что вы ищете.

Указывается в документах как void xmlStopParser(xmlParserCtxtPtr context).

Документация доступна здесь: http://xmlsoft.org/html/libxml-parser.html#xmlStopParser

Также у Алекса Дима есть хороший совет в этой теме: Можно ли остановить синтаксический анализатор libxml во время работы процесса?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...