Formatting html tags in Objective-C

痞子三分冷 提交于 2019-12-02 17:57:49

问题


I am reading an data from an XML file for my iPhone application. This data contains html tags such as <p></p> <strong> <B>, etc in it. By using NSString class can i remove these tags and format the display of the text as needed.

For example, if text inside the <p> </p> i want to display it in next paragraph. Is it possible?

Please suggest.

Any help would be appreciated.

-Sathiya


回答1:


Why not leave the formatting in place, and use either a UIWebView to display the text or a TTStyledTextLabel from the Three20 project.




回答2:


Mmm... Only me doesn't see an example? But you can insert @"\n" to move text to the next line in your UITextView or console.




回答3:


There is a library on the iPhone to do HTML parsing, but it takes a bit more work than using NSString. However, it will give you a lot more control. You can walk the HTML tree and pick out the parts that interest you.

Look at libxml2's html reader:

http://xmlsoft.org/html/libxml-HTMLparser.html#htmlReadMemory



来源:https://stackoverflow.com/questions/1620423/formatting-html-tags-in-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!