views:

217

answers:

1

Hey guys, has any of you some experience with parsing HTML with the TouchXML lib on the iPhone. I would like to parse some html and therefore try to do the following

self.parser = [[CXMLDocument alloc]initWithData:self.html options:0 error:&error1];

 if (error1) {
  NSLog(@"Error: %d", error1);
 }

 NSError *error;

 NSArray *resultNodes = [[NSArray alloc]init];

 NSLog(@"starting to do some crazy parsing");


 resultNodes = [self.parser nodesForXPath:@"//div" error:&error];
 if (error)
  NSLog(@"initWithData error : %d", error);

Unfortunately that does not work at all. And I dont know how to debug this properly. My HTML should be valid. It simply starts with a html tag, meaning there is no doctype. The initWithData method already seems to crash and returns the following error: Error: Error Domain=CXMLErrorDomain Code=-1 "The operation couldn’t be completed. (CXMLErrorDomain error -1.)" If I try to output the second error the app crashes before, probably cause of the fact that initWithData does not work.

Has anyone of you made some experience with parsing HTML with the TouchXML lib?

Thanks for any help!

A: 

First and foremost, error is a pointer to an object, so if you want to print it out. It should be : NSLog(@"%@", error1); The same for error. If you want to print error code. You can do NSLog(@"%d", [error1 code]). What you give us is just the memory area of the error

vodkhang
Error: Error Domain=CXMLErrorDomain Code=-1 "The operation couldn’t be completed. (CXMLErrorDomain error -1.)"
Dude
The above is what is returned when I print out the error
Dude
Actually when I print error1. It crashes when I try to print out error, which is the second in the example
Dude
It crashes when you print out error1, looks strange for me. I think because you can not initWithData:, you cannot do anything
vodkhang
Yeah, I guess the problem is that initWithData does not work...
Dude