0

My XML file have the Chinese Characters, which are Big-5, how to convert it to UTF-8 based on below code?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSString *xmlFilepath = [[[NSBundle mainBundle] resourcePath]  stringByAppendingPathComponent:@"Hostels.xml"];


    NSData *xml = [[NSData alloc] initWithContentsOfFile:xmlFilepath];



    NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:xml];

    Parser *theParser = [[Parser alloc] initParser];

    [xmlParser setDelegate:theParser];

.......
Gere Tan
  • 43
  • 5

1 Answers1

0

Try to use this piece of code to extract Big-5 encoded Chinese characters

//-2147481085,  // Traditional Chinese (Big 5)
//-2147481082,  // Traditional Chinese (Big 5 HKSCS)
//-2147482589,  // Traditional Chinese (Windows, DOS)
//-2147483646, //Traditional Chinese (Mac OS)
#define NSBIG5Encoding -2147482589
NSString* content = [NSString stringWithContentsOfFile:fileParh_
                                              encoding:NSBIG5Encoding
                                                 error:nil];
NSData *XMLData = [content dataUsingEncoding:NSUTF8StringEncoding];
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:XMLData];
gnat
  • 6,213
  • 108
  • 53
  • 73
Simon
  • 17,223
  • 1
  • 19
  • 23