我该如何解析HTML?

时间:2011-08-17 08:04:05

标签: iphone html xml

假设我有以下字符串:

NSString * str = "<a href="http://www.google.com"style="">
</br>
<a href="http://www.google.com" id="" style="">Come on</a>hello world"

如何解析锚标记的值 - “加油”?

我应该使用HTMLNode.h和HTMLParser.h吗?例子将不胜感激。

2 个答案:

答案 0 :(得分:1)

如果它是静态的,那么你可以使用字符串操作从标记

中取出子字符串

OR

如果它是动态的并且html / xml代码不断变化,那么你可以使用NSXMLParser。请记住,最好只在数据采用XML格式时才使用NSXMLParser。

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html

希望这有帮助。

答案 1 :(得分:1)

libxml2非常擅长解析xml / html,请看这个链接:http://cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html

相关问题