So I have some HTML text that I would like to display in a tableView.
I have two UITableView cells. A quote cell and a ‘non-quote’ cell.
I need to be able to break this HTML up into an array where the quotes are displayed properly
In other words The following html:
<div class='comment'>
This is some text before the quote
<div class='quote'>
This is some text in a quote
</div>
This is between the quotes
<div class='quote'>
This is text in another quote
<div class='unrelatedDiv'>
this is in an unrelated div
</div>
</div>
This is some text after the quote
</div>
Would look something like this in an array when finished.
This would then be loaded into my tableView which would know there are 5 sections and that 1 and 3 are suppose to be quotes.
[0] => "This is some text before the quote"
[1] => "This is some text in a quote"
[2] => "This is between the quotes"
[3] => "This is text in another quote \n this is in an unrelated div"
[4] => "This is some text after the quote"
I would use DTHTMLParser from the DTCoreText project for this. It is an Objective-C wrapper around libxml2.
For your example HTML, you would see delegate calls such as these, in the order of their appearance:
So you can basically just use the
[DTHTMLParser parser:foundCharacters:]delegate method.