0

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!

1
  • Can you edit your code to make it look better?
    – vodkhang
    Jul 21, 2010 at 15:15

2 Answers 2

0

Following have been working absolutely fine for me. Try it.

 CXMLDocument *rssParser = [[[CXMLDocument alloc] initWithContentsOfURL:url options:0 error:nil] autorelease];
resultNodes = [rssParser nodesForXPath:@"//item" error:nil];

// Loop through the resultNodes to access each items actual data
for (CXMLElement *resultElement in resultNodes) {
  ....

Also make sure that your link is right. Couple of times it happened to me while I was using feed://www.foo.com/feed instead of http://www.foo.com/feed

Cheers.

0

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

3
  • Error: Error Domain=CXMLErrorDomain Code=-1 "The operation couldn’t be completed. (CXMLErrorDomain error -1.)"
    – Dude
    Jul 21, 2010 at 15:22
  • Actually when I print error1. It crashes when I try to print out error, which is the second in the example
    – Dude
    Jul 21, 2010 at 15:25
  • It crashes when you print out error1, looks strange for me. I think because you can not initWithData:, you cannot do anything
    – vodkhang
    Jul 21, 2010 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.