开发者

iPhone, parsing HTML with TouchXML

开发者 https://www.devze.com 2023-01-08 01:28 出处:网络
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

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 m开发者_运维百科ethod 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!


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消