开发者

Objective C HTML parser error "expected expression before xmlNode"

Was following this Simple libxml2 HTML parsing example, using Objective-c, Xcode, and HTMLparser.h and http://benreeves.co.uk/objective-c-hmtl-parser/

The author notes that there's something wrong with rawContentsOfNode method.

NSArray *bodytext = [bodyNode findChildTags:@"td"];

for (HTMLNode *inputBody in bodytext) {
    //NSLog(@"%@", [inputBody getAttributeNamed:@"class"]);
    NSString *test = rawContentsOfNode(xmlNode *bodytext, htmlDocPtr doc);
}

There doesn't seem to be any example of using the updated version. and I can't figure out whats wrong. Any help with fixing this开发者_如何学编程 would be great.


The example in the StackOverflow answer won't even compile because he has just copy-pasted the note in the original example.

This:

rawContentsOfNode(xmlNode *bodytext, htmlDocPtr doc);

is part of a function prototype not a function call. It's a C function that requires and xmlNode and a htmlDocPtr as parameters. Looking at the interface of HTMLNode, we see that the prototype given in the comment is wrong, it should be:

NSString* rawContentsOfNode(xmlNode *node);

There's no mention in the source code of a function matching the prototype recommended in the blog post. I have no idea what they were talking about, unless it has been removed since the comment was made.

The XML node is a public member of the HTML node, so you could do:

test = rawContentsOfNode(inputBody->_node);

But the method rawContents does that anyway so you might as well use it.

test = [inputBody rawContents];

Note that (again checking the source code) there is an issue in that the content of the node is assumed to be encoded in UTF-8 this may be true, but the default encoding for HTTP is ISO-8859-1 so it may not.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜