I am using the FSharp.Data for downloading and parsing an XML document. The document contains several nordic characters, like: "Lempäälän Keskus". I have a simple code like this:
open FSharp.Data
open System.IO
let xml = Http.RequestString(downloadUrl)
File.WriteAllText("response.xml", xml)
However, when I open the resulting file, the characters are corrupted and I see this: "Lempäälän Keskus". I have tried manually re-saving the file with the ISO-8859-1 encoding and then reopening with UTF-8 (in VS Code). This fixed the displayed text. Then tried to implement a simple encoding conversion function:
open FSharp.Data
open System
open System.IO
let convertEncoding (input: string) =
let iso = Encoding.GetEncoding("ISO-8859-1")
let utf8 = Encoding.UTF8
let isoBytes = iso.GetBytes(input)
let utfBytes = Encoding.Convert(iso, utf8, isoBytes)
utf8.GetString(utfBytes)
let xml = Http.RequestString(downloadUrl)
let decoded = convertEncoding xml
File.WriteAllText("response.xml", decoded)
However, when I open the file, I still see "Lempäälän Keskus" instead of "Lempäälän Keskus". What am I doing wrong?