#File Enconding

13 messages · Page 1 of 1 (latest)

upper shoal
#

Hello guys! First timer here and begginer on GO!

I am now working on a project where I have a XML that gets generated by PHC and my GO code must read that file, authenticate via Graph API and send an email with the contents of said XML. However, I am having a lot of trouble with encoding.
When I receive the email (for testing purposes) it is all out of format.
I've read that GO uses UTF-8 by default, but I the XML I receive is formated with iso-8859-1 and apparently (not quite sure) Graph API also "stamps" the email with a Windows-1252 encoding.

I am desperate because I can't solve this issue and i've tried for 2 whole days and even asked ChatGPT for help but it didnt do much.

Some help would be very much appreciated!

#

File Enconding

cerulean turtle
#

If the first 4 bytes are valid UTF-8 then it should be read as UTF-8. The optional encoding attribute in the header will tell you if it's not UTF-8.

cerulean turtle
#

Are you parsing the XML or do you only want to attach it to an e-mail?

swift oxide
#

and ISO8859_1 for the other

upper shoal
#

@swift oxide but will I need to do it twice? Or just for the encoding of the XML?

swift oxide
#

why twice? you do it for stuff that isn’t already utf8

cerulean turtle
#

Does the XML use namespaces?

#

Can you provide a minimum viable example of what the XML looks like and I might be able to help you.
Just strip out the sensitive info. Just put in dummy addresses and text etc.

#

Also, don't forget to set the content type when you send the e-mail. Go will output strings in UTF-8 unless you make it output something different.