views:

413

answers:

1

I'm trying to make an XPath query with TouchXML, but if the query fail, the programm crash immmediately.

Is there any way to prevent this and continue the execution of the programme.

I know that TouchXML is based on libxml2 and that lib have an option called XML_PARSE_RECOVER but i don't know how to use it with TouchXML.

Source code

- (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; 
}

I try to make a wrong XPath query like that : //x:div[@cla

And I get :

XPath error : Invalid predicate
A: 

i am using a normal

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