2011-04-27 58 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; 
}