包含以下解决方案。可可CF具有CFXMLCreateStringByUnescapingEntities函数,但在iPhone上不可用。
@interface MREntitiesConverter : NSObject <NSXMLParserDelegate>{ NSMutableString* resultString;}@property (nonatomic, retain) NSMutableString* resultString;- (NSString*)convertEntitiesInString:(NSString*)s;@end@implementation MREntitiesConverter@synthesize resultString;- (id)init{ if([super init]) { resultString = [[NSMutableString alloc] init]; } return self;}- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)s { [self.resultString appendString:s];}- (NSString*)convertEntitiesInString:(NSString*)s { if (!s) { NSLog(@"ERROR : Parameter string is nil"); } NSString* xmlStr = [NSString stringWithFormat:@"<d>%@</d>", s]; NSData *data = [xmlStr dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]; NSXMLParser* xmlParse = [[[NSXMLParser alloc] initWithdata:data] autorelease]; [xmlParse setDelegate:self]; [xmlParse parse]; return [NSString stringWithFormat:@"%@",resultString];}- (void)dealloc { [resultString release]; [super dealloc];}@end
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)