问题
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