Can't get UTF-8 characters from XML file displayed correctly (Cocoa Touch)

Hi there,

I'm trying to read an XML file with Japanese and Korean characters (encoded UTF-8) into a String like

NSString *s = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://.../data1.xml"] encoding:NSUTF8StringEncoding error:&e];

However, the output just gives me some wrong characters. I also tried use NSData, but the result was the same.

The same when I parse the XML file with

NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:URL];

The parser function just gives back gibberish.

When I write the data into a table cell (cell.text = ...), only the first character is displayed followed by "...".


Where can I start looking to get this right? I'm not so experienced in Cocoa yet, so I feel that I'm missing something simple here...

Thanks,
Thomas

iPod Touch, Mac OS X (10.5.5)

Posted on Oct 2, 2008 9:54 AM

Reply
6 replies

Oct 2, 2008 5:36 PM in response to orangekay

I think so (haven't checked), but it is a really simple test xml which is not really error prone).
But the problem is a different one, because I also just tried to read a txt file with some Japanese characters into an NSString using initWithContentsOfURL.
When I print the string in the console, I only get messed up characters (the latin characters next to the Japanese are displayed fine).

It is a general problem of reading out an UTF-8 file from an url.

Spent the whole last night to google something helpful but couldn't find anything. Now I'm tired at work 😉

Thomas

Oct 3, 2008 2:40 AM in response to orangekay

I validated the xml, it is fine. When I open the file in any editor like SubEthaEdit, it says UTF-8 and the characters are fine.
However, when I use QuickLook to look into the xml file, the same weird characters are shown instead of the Japanese ones.

I have the file at homepage.mac.com/thomasgoerlich/data1.xml if somebody wants to have a look. The content is really just some random data for me to test.

Thomas

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Can't get UTF-8 characters from XML file displayed correctly (Cocoa Touch)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.