Just create an interface by following this code.
@interface MREntitiesConverter : NSObject {
NSMutableString* resultString;
}
@property (nonatomic, retain) NSMutableString* resultString;
- (NSString*)convertEntiesInString:(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*)convertEntiesInString:(NSString*)s {
if(s == nil) {
NSLog(@”ERROR : Parameter string is nil”);
}
resultString = [[NSMutableString alloc] init];
NSString* xmlStr = [NSString stringWithFormat:@"%@ ", s];
NSData *data = [xmlStr dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSXMLParser* xmlParse = [[NSXMLParser alloc] initWithData:data];
[xmlParse setDelegate:self];
[xmlParse parse];
NSString* returnStr = [[NSString alloc] initWithFormat:@”%@”,resultString];
[resultString release];
return returnStr;
}
- (void)dealloc {
//[resultString release];
[super dealloc];
}
@end
When you want to decode HTML characters within a string, just call the app like this.
MREntitiesConverter *converter = [[MREntitiesConverter alloc] init];
someStr = [converter convertEntiesInString:@"abcdefghiijXXXYZ"];
[converter release];
Easy enough?