On Thu, 3 Sep 2015 07:04:20 -0700 (PDT)
"Tobias S." <
tobias....@gmail.com> wrote:
>
> Thanks for your clarification. My problem now seems to be the BOM.
> The code looks like this:
>
> b, _ := ioutil.ReadAll(xmlFile)
> text := strings.NewReader(string(b))
> decoder := xml.NewDecoder(text)
> decoder.CharsetReader = charset.NewReaderLabel
Overengeneered. os.File already implements io.Reader,
so just do
decoder := xml.NewDecoder(xmlFile)
decoder.CharsetReader = charset.NewReaderLabel
> When I print out the text variable I get:
>
> &{??<?xml version="1.0" encoding="UTF-16"?>
>
> At the start of the file. The two leading question marks are probably
> the BOM marks. I get the error message:
>
> XML syntax error on line 1: invalid UTF-8
>
> from the decoder....
OK, so I'd then employ buffering and its ability to "peek" at the data,
literally, and discard it, if needed:
http://play.golang.org/p/zGrNnYRkPF