Simple libxml2 HTML parsing example, using Objective-c, Xcode, and HTMLparser.h

Posted by Stu on Stack Overflow See other posts from Stack Overflow or by Stu
Published on 2010-06-11T07:10:25Z Indexed on 2010/06/11 7:12 UTC
Read the original article Hit count: 1829

Please can somebody show me a simple example of parsing some HTML using libxml.

#import <libxml2/libxml/HTMLparser.h>

NSString *html = @"<ul><li><input type=\"image\" name=\"input1\" value=\"string1value\" /></li><li><input type=\"image\" name=\"input2\" value=\"string2value\" /></li></ul><span class=\"spantext\"><b>Hello World 1</b></span><span class=\"spantext\"><b>Hello World 2</b></span>";

1) Say I want to parse the value of the input whose name = input2.

Should output "string2value".

2) Say I want to parse the inner contents of each span tag whose class = spantext.

Should output: "Hello World 1" and "Hello World 2".

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about xcode