FAQ
I am using "encoding/xml" to decode xml. Like this:

     import (
         "github.com/paulrosania/go-charset/charset"
         _ "github.com/paulrosania/go-charset/data"
         "encoding/xml"
         "os"
     )

...

     d := xml.NewDecoder(os.Stdin)
     d.CharsetReader = charset.NewReader
     var s myType
     err = d.Decode(&s)

This works for utf-8, iso-8859-1, others... but when I try to decode xml
that is in utf-16 (including a byte order mark) I get:

     XML syntax error on line 1: invalid UTF-8

Using xml.Unmarshal gives the same error.

I know, utf16 is weird, but Windows programs seem to produce it. And
at http://www.opentag.com/xfaq_enc.htm it reads:

     All XML processors must support at least UTF-8 and UTF-16.

So why isn't utf-16 (and utf-32) supported?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Patrick Mézard at Oct 29, 2015 at 7:55 am

    On 28/10/15 22:32, Peter Kleiweg wrote:
    I am using "encoding/xml" to decode xml. Like this:

    import (
    "github.com/paulrosania/go-charset/charset"
    _ "github.com/paulrosania/go-charset/data"
    "encoding/xml"
    "os"
    )

    ...

    d := xml.NewDecoder(os.Stdin)
    d.CharsetReader = charset.NewReader
    var s myType
    err = d.Decode(&s)

    This works for utf-8, iso-8859-1, others... but when I try to decode xml that is in utf-16 (including a byte order mark) I get:

    XML syntax error on line 1: invalid UTF-8

    Using xml.Unmarshal gives the same error.

    I know, utf16 is weird, but Windows programs seem to produce it. And at http://www.opentag.com/xfaq_enc.htm it reads:

    All XML processors must support at least UTF-8 and UTF-16.

    So why isn't utf-16 (and utf-32) supported?
    Maybe combine https://godoc.org/golang.org/x/text/encoding/unicode#BOMOverride with from https://godoc.org/golang.org/x/text/transform#NewReader to wrap your input reader and handle UTF-16 automatically (I have not tried it).

    --
    Patrick Mézard

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedOct 28, '15 at 9:32p
activeOct 29, '15 at 7:55a
posts2
users2
websitegolang.org

2 users in discussion

Patrick Mézard: 1 post Peter Kleiweg: 1 post

People

Translate

site design / logo © 2021 Grokbase