0

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

That is awesome. thank you very much. damn i thought i tried that already -_-.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.