Hi,
How can I handle special characters while using unmarshalling. I am getting
some special charactes in my xml data (like this eg êÿÿ ) and golang
throwing xml syntax error invalid UTF-8. Any please suggest how to handle
this case.
I tried to handle this xml decoder like this:
// Decoder_p.go
package main
import (
"fmt"
"encoding/xml"
"io"
"strings"
)
type Message struct {
Mon string `xml:"monitor"`
Data string `xml:"data"`
}
func main() {
fmt.Println("Hello World!")
xml_data := "<monitor>CPU</monitor><data>êÿ</data>"
var reader io.Reader
reader=strings.NewReader(xml_data)
val:=*strings.NewReader(xml_data)
fmt.Println(reader,val)
//read,_ := reader.Read([]byte(xml_data))
//result,err := io_reader.Read([]byte(xml_data))
//if err == nil {
decoder := xml.NewDecoder(reader)
//decoder.CharsetReader = func(data string,io
io.Reader)(io.Reader,err)
//decoder.RawToken()
out := Message{}
err := decoder.Decode(&out)
fmt.Println(out)
fmt.Printf(out.Data,out.Mon)
fmt.Println(err)
//}
}
but I am getting empty structure.
output:
Hello World!
&{<monitor>CPU</monitor><data>êÿ</data> 0 -1}
{<monitor>CPU</monitor><data>êÿ</data> 0 -1}
{ }
%!(EXTRA string=)<nil>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.