Friday 29 November 2019

Golang ISO-88591-1 XML Decoder

Recently I had to decode XML files in ISO-88591-1 charset, there are quite a few threads and blogs around, but none seemed to work, most present workarounds and then just the standard way from 2015 onward, but it does not work, at least not in my case. This simple implementation of CharsetReader works for me. // <?xml version="1.0" encoding="ISO-88591-1"?>



func MyCharsetReader(charset string, input io.Reader) (io.Reader, error) {
    fmt.Printf("XML Charset: %s\n", charset)
    switch charset {
    case "ISO-88591-1":
        return transform.NewReader(input, charmap.ISO8859_1.NewDecoder()), nil     }
    return nil,nil
}

func main() {

    dec := xml.NewDecoder(os.Stdin)

    dec.CharsetReader = MyCharsetReader
    dec.Strict = false

 

Chipmaster Gear Cutting

  Calculate all the possible gear combinations for the gear selector to cut a 15TPI thread: Imperial TPI C 5 24 20 Imperial TPI ...