UITableView. Rather than go through the effort of parsing HTML on the iPhone (as I already parsed the XML file) I built this simple method from some half-finished snippets I found. It has worked in all of the cases I have needed, but your mileage may vary. It is at least a working method (which cannot be said about most of the other examples). It works on the iPhone and in standard OS X coding.
- (NSString *)flattenHTML:(NSString *)html {
NSScanner *theScanner;
NSString *text = nil;
theScanner = [NSScanner scannerWithString:html];
while ([theScanner isAtEnd] == NO) {
// find start of tag
[theScanner scanUpToString:@"<" intoString:NULL] ;
// find end of tag
[theScanner scanUpToString:@">" intoString:&text] ;
// replace the found tag with a space
//(you can filter multi-spaces out later if you wish)
html = [html stringByReplacingOccurrencesOfString:
[ NSString stringWithFormat:@"%@>", text]
withString:@" "];
} // while //
return html;
}
hi, thanks sir
hi, thanks sir
Thank you! Just what I
Thank you! Just what I searched for!
Hi, I'm having trouble
Hi, I'm having trouble reading your site in the Avant browser (the font size it way too small). I've tried raising the font size from my browser but that didn't do the trick. Do you have any tips on what I can do? (By the way, I'm using Windows Vista) - ways to lose weight after baby
Hey man, thanks for the
Hey man, thanks for the tip!
Some of my returned strings were starting off with spaces, so I tacked on a bit of code to the end:
// Trimmed return
return [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
THANK you very much!!! You
THANK you very much!!! You save me a lot of time!!! you make my day!!!!!!!
As others have wondered:
As others have wondered: where would this go? Would I put this in the parser?
It just takes a string as
It just takes a string as input, so it can go anywhere you want it. I'd grab the contents of a URL (slurp it into an NSString) and then pass it through here before doing anything else with it. Remember, it's for stripping tags from HTML pages, not sifting through an XML file.
this snippet is pretty good:)
this snippet is pretty good:) thanx for this
http://netdeveload.wordpress.com for .net development
Thank you very much, I have
Thank you very much,
I have used a code almost equal as this one for my projects, and it worked perfectly, but very slow. I need a more optimized solution.. I think I'll will try to convert to a C string, and do the parsing in plain C..
cheers
Wow, like everyone else has
Wow, like everyone else has said, Thank you! I've been looking for something like this and nothing ever seemed to really work right but this is great. Again, much appreciated!
Where did you put this
Where did you put this snippet? Any help would be appreciated.
*from a frustrated would-be app coder*
works perfect for me! Great
works perfect for me! Great thanks!
Where do you place this code?
Where do you place this code? In the view controller or rss parser? I would like to use this in my rss reader app and cannot get the html tags out of the blog detail view.
Thanks, that worked well for
Thanks, that worked well for flattening rss feeds.
Thank you so much!! THat has
Thank you so much!! THat has really solved a big problem for me.
Thanks a lot for this
Thanks a lot for this snippet! Had the same issue of already parsing an XML and not wanting to do it again :)
After used this code, i'm
After used this code, i'm getting my contents. But it is completely messed up with white spaces as it is big 4 paragraph srtring. I don't how to remove only the uneccessary white spaces. Author should have written that code sample too..waiting ..
Change: withString:@"
Change:
withString:@" "
to
withString:@"".
Should work fine.
Awesome, thanks a
Awesome, thanks a million!!!!! I tried a number of things... adapting to Objective C is great with a community that helps push adoption of techniques. Thanks again.
thanks. worked well for
thanks. worked well for flattening rss feeds.
Much thanks for this code
Much thanks for this code snippet. I have been messing around with the TouchXML libraries only to realize that they did not output XML (only read it) and was beginning to get frustrated. Its very bad when you know *how* to do something but you don't know the underlying libraries to accomplish it.
Great little snippet. Thanks again,
jb