Right now I am working on a small project which requires me to pull some table from a website. I read some posts which suggests using NSXMLParser and some have suggested libxml2.2.dylib. Which of these would be easier to use? I only need to get a few values from the page, nothing too co开发者_JAVA百科mplicated.
NSXMLParser; especially if your needs aren't that deep. There are also some external libraries to consider: TouchXML.
I'm also parsing HTML in my current project and i use GDataXML for that which uses libxml2 underneath. It lets you use XPath and in my case it reduces the parsing code to just a few lines and i prefer it over NSXMLParser. Depending on the performance you need XPath might not be the best option for you - in my case it's fast enough though.
A brief example on how you would get all tables out of the body of your html:
GDataXMLDocument* xmlDocument = [[GDataXMLDocument alloc] initWithXMLString:htmlString options:0 error:nil];
NSArray* tablesInBody = [xmlDocument.rootElement nodesForXPath:@"body/table" error:nil]
精彩评论