XML output to UTF-8 - what do I need to do?

Hi,

I am writing an xml-creation routine to save data to an online file using the www class and a PHP-script. Previously when doing things like this I have relied on NET classes, but since this is for iOS I want to avoid these. The only point I quite don’t understand is what (if anything) I need to do to ensure character encoding is working as it should (I want to go to UTF-8).

How do I ensure the string I send out is using the proper encoding? I am using C#, which I understand uses unicode internally, but again - don’t understand what I need to do to go to UTF-8.

Many thanks in advance for any help and sorry for the blatant ignorance! :slight_smile:
Cheers,
Dan

you are always relying on .NET classes …

As for encodings: Check the System.Text framework and the encodings in there thats how you transform them

Thanks for your reply.
Well, yes I do know Unity is relying on NET - my intended meaning of that phrase was that I do not want to rely on System.XML or other large DLLs since I target iOS and want to optimize the size. Is System.Text also large in size? If so that is a no go as well.

//Dan

well if you want encoding its not a matter of go or no go.
You can use it or you are by definition always on Unicode

public static string UTF8ByteArrayToString(Byte[] characters)
{
    return System.Text.Encoding.UTF8.GetString(characters, 0, characters.Length);
}

public static Byte[] StringToUTF8ByteArray(String text)
{
    return System.Text.Encoding.UTF8.GetBytes(text);
}

Wrapped in temporary methods to help explain their usage.

EDIT: re-read the needs of the poster, this may not be what you need to convert Unicode to UTF8. Though if you use this and transfer your data as raw byte data to your PHP script, then you can be sure you can decode it as UTF8 on the server and vice versa.

Many thanks for the help! I still have to check up on the (possible) impact of System.Text on the build size, but it is likely very inconvenient to roll my own UTF8 encode/decoder so I suspect the impact will be worth it. (As opposed to the XML class which is quite bloated for most common needs).

Again, many thanks!