I'm using NSXMLParser to parse a RSS XML file but I get html tags in my description string. I'm trying to know which way is the best to parse html tags and encode to plain text to store in a string. I'm doing something like this:
func parser(parser: NSXMLParser, foundCharacters string: String) {
var error: NSError?
switch feedElement! {
case "title":
if feedTitle != nil {
feedTitle! += string
}
case "link":
if feedLink != nil {
feedLink! += string
}
case "description":
if feedDescription != nil {
feedDescription += string
}
default:
break
}
}
I've also tried something like this but my app just turns very very slow.
case "description":
if feedDescription != nil
var plainString = NSAttributedString(data: NSData(data: string .dataUsingEncoding(NSUTF8StringEncoding)!), options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: NSNumber.numberWithInt(1)], documentAttributes: nil, error: &error)
feedDescription += plainString.string
}
Thank you in advance.
No comments:
Post a Comment