2011-04-27 56 views
0

如何從解析XML中刪除HTML實體? 意味着我解析XML,但我不能刪除<br/>&nbsp;分析時解析html屬性

+0

發佈HTML代碼時,請使用反碼(\「
\')來轉義它們,否則它們將不會顯示在您的帖子中。 – nash 2011-04-27 06:52:14

回答

2
[NSString stringByReplacingOccurrencesOfString:@","withString:@""]; 

嘗試使用此功能,替換符號巫婆你想要的。

+0

你在做什麼? – 2011-04-28 06:14:07

4

你的意思是這樣的嗎?

/** 
* Removes the HTML tags found in the string 
* @param html the string to scan 
* 
* @returns the original string without tags 
*/ 
- (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 
    html = [html stringByReplacingOccurrencesOfString: 
      [NSString stringWithFormat:@"%@>", text] 
              withString:@" "]; 
    } // while // 

    return html; 
}