views:

24

answers:

1

Hi!

First I parse XML and retrieve this:

<p><strong>Berns Salonger - the City's

The I decode it with MWFeedParser (stringByDecodingHTMLEntities) and retrieve this:

<p><strong>Berns Salonger - the City's Ideal Meeting Place 

Note that this is only one line of many many lines which includes alot of
tags.

Then I replace
with \n and the console writes out the text with new lines. Everything is great except that all the other HTML tags is still there.

So I then run stringByConvertingHTMLToPlainText and all HTML tags dissapears. But also my replaced new lines.

How can I decode HTML without and at the same time replace
with \n to print out a nice formatted text in a UITextView?

+1  A: 

Instead of replacing <br> with \n, try replacing it with an HTML entity for newline: &#10;. Then, when you call stringByConvertingHTMLToPlainText, it will convert the entity to an actual newline character.

Josh Hinman
If I want to replace <p> and </p>? I can't fint the HTML entity for that. I thought it was ¶ but it wasn't.
Fernando Redondo
I tried with: contentText = [contentText stringByReplacingOccurrencesOfString:@"<p>" withString:@"<p>"]; contentText = [contentText stringByReplacingOccurrencesOfString:@"</p>" withString:@"</p>"];But that didn't work either.
Fernando Redondo
Use the same entity for <p>: Maybe use two of them for double spacing.
Josh Hinman