你们中有人有在 iPhone 上使用 TouchXML 库解析 HTML 的经验吗?我想解析一些 html,因此尝试执行以下操作,
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);
不幸的是,这根本不起作用。而且我不知道如何正确调试它。我的 HTML 应该有效。它只是以 html 标签开头,这意味着没有文档类型。 initWithData 方法似乎已经崩溃并返回以下错误:
错误:错误域=CXMLErrorDomain代码=-1“操作无法完成。(CXMLErrorDomain错误-1。)”如果我尝试输出第二个错误,应用程序之前崩溃,可能是由于initWithData不起作用。
你们中有人有过使用 TouchXML 库解析 HTML 的经验吗?
感谢您的帮助!
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!
发布评论
评论(2)
以下对我来说工作得非常好。尝试一下。
还要确保您的链接正确。有几次当我使用 feed://www.foo.com/feed 而不是 http://www.foo.com/feed 时,这种情况发生在我身上/www.foo.com/feed
干杯。
Following have been working absolutely fine for me. Try it.
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.
首先也是最重要的,error是一个指向对象的指针,所以如果你想把它打印出来。它应该是:
NSLog(@"%@", error1);
错误相同。如果你想打印错误代码。您可以执行NSLog(@"%d", [error1 code])
。你给我们的只是错误的内存区域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 doNSLog(@"%d", [error1 code])
. What you give us is just the memory area of the error