2009-04-14 6 views
0

TouchXML로 오류를 복구하려고 시도합니다. 을 사용하여 XPath 쿼리를 작성하려고하지만 쿼리가 실패하면 즉시 프로그램이 중단됩니다.

이 문제를 방지하고 프로그램 실행을 계속할 수있는 방법이 있습니까?

TouchXML은 libxml2을 기반으로하고 lib에는 XML_PARSE_RECOVER이라는 옵션이 있지만 TouchXML과 함께 사용하는 방법을 알지 못합니다.

소스 코드

- (id)initWithData:(NSData *)d 
{ 
    if (![super init]) 
     return nil; 
    NSError *error; 

    translation = [[WRTranslation alloc] init]; 
    parser = [[CXMLDocument alloc] initWithData:d options:0 error:&error]; 

    if (error) 
     NSLog(@"initWithData error = true"); 

    return self; 
} 

- (void)dealloc 
{ 
    NSLog(@"dealloc de WRTouchParser = %@", self); 
    [translation release]; 
    [parser release]; 
    [super dealloc]; 
} 

- (BOOL)queryData:(NSString *)s 
{ 
    // Nécessaire pour faire une requête. Exemple : //x:div[@class="se"] 
    NSDictionary *mappings = [NSDictionary dictionaryWithObject:@"http://www.w3.org/1999/xhtml" forKey:@"x"]; 
    NSArray *res = [parser nodesForXPath:s namespaceMappings:mappings error:nil]; 

    queryResult = [res description]; 

    return YES; 
} 

나는 그런 잘못된 XPath 쿼리 만들려고 : // X : DIV [@cla

를 내가 얻을 : 내가 사용하고

XPath error : Invalid predicate 
+0

사용중인 코드를 게시 할 수 있습니까? 전자의 세부 사항? TouchXML을 사용하지는 않았지만 충돌이 발생하면 문제가있는 것처럼 들립니다. –

+0

틀린 XPath 쿼리를 실행하는 경우에만 :'// x : div [@ cla' –

답변

1

보통

@try { 
    ... 
} @catch (NSException *e) { 
    ... 
}