解析时解析html属性

时间:2011-04-27 06:43:04

标签: iphone objective-c ios4

如何从解析XML中删除HTML实体? 意味着我正在解析XML,但我无法删除<br/>&nbsp;等。

2 个答案:

答案 0 :(得分: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;
}

答案 1 :(得分:2)

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

尝试使用此功能,替换你想要的符号。