Encodings. :(

I know the answer is encodings, but I need a hint…

Right now, using Xojo up to 2013, I have text areas in which users can type anything/
So in german, they may type something like this:

As part of an archiving system, I put the text into an XML document.
This is where the fun starts.

My first attempts were fine, until the text included special characters such as ; and &, because these broke the XML parser.
To avoid that, I started using Encodebase64 on the way in, and decodebase64 on the way out.
XML Parser is now happy.

But during the unpacking, accented characters lose the encoding, I guess.
So Freundliche Grüße becomes Freundliche GrA1/4e or something similar.

I thought that Xojo normally worked in UTF8.
The text I encode will be in that encoding.
And the text I decode goes straight back into a Xojo string which should still be the same (default) encoding, shouldnt it?

What am I missing?

Jeff I also have to deal with german text and XML, but had not problems at all.
Maybe you didn’t keep in account that reading text from a file, it provides you unknown encoding (because it’s not possible to determine the encoding from a text file). So, if you are sure the read text is UTF-8 (as it should), you can just use

newText = DefineEncoding(myText, Encodings.UTF8)

to define the right encoding.

Btw, for simple UTF-8 text you don’t need to encode it in Base64.

Thanks.
I have definitely had problems putting utf8 text into an XML attribute, which I solved by encodebase64
I’m assuming it was a character like & or ; , rather than an accented character.

But setting defineencoding on the way back out solves the German/French issues.
Thanks

Keep in mind XML is UTF-8 encoded and it automatically handle writing chars like &.
In the end you have to do nothing but set the right encoding on reading back the XML file.
If you read it as a binary file, use the DefineEncoding() pointed above.
If you instead read it as text file, you can define the encoding on opening the TextInputStream.

I use to write in spanish ( , … and portuguese) a personal function, but is similar to this example:

plataform: Win 7,32 bits

  1. To save the info in a database i use similar to:
dim ResultToSave as string
dim youText as string
yourText = (get from textfield, or ...)
ResultToSave = yourText.ConvertEncoding(Encodings.ISOLatin1)

... action to save
  1. To restore the info from database i use similar to:
.... definitions...
yourText = (... from database...)
resultToView  = yourText.DefineEncoding(Encodings.UTF8)

[quote=218266:@Ruben Dieminger]I use to write in spanish ( ñ,ó,á, … and portuguese) a personal function, but is similar to this example:

plataform: Win 7,32 bits

  1. To save the info in a database i use similar to:
dim ResultToSave as string
dim youText as string
yourText = (get from textfield, or ...)
ResultToSave = yourText.ConvertEncoding(Encodings.ISOLatin1)

... action to save
  1. To restore the info from database i use similar to:

.... definitions... yourText = (... from database...) resultToView = yourText.DefineEncoding(Encodings.UTF8) [/quote]

Sorry but this seems wrong to me: you first convert to ISOLatin1 and save, then you get the text and Define the encoding to UTF-8
In the second step you should Convert again to UTF-8, not Define.

Propably something like this:

resultToView  = yourText.DefineEncoding(Encodings.ISOLatin1).ConvertEncoding(Encodings.UTF8)

So first tell what it is, and then convert to what you want.

Jukka