Thanks. On Fri, Jan 25, 2019 at 2:54 PM Wagner Riffel <wgrrif...@gmail.com> wrote:
> there is nothing to do with special characters in the example you > shown, your xml data is just invalid xml, you're missing root element, > just add it and it should work: > <rootElem><monitor>CPU</monitor><data>êÿ</data></rootElem> > btw here is a short version of your program on playground, > https://play.golang.org/p/PhKgVXIcWZl > > On Fri, Jan 25, 2019 at 6:25 AM <durgasomeswararao...@gmail.com> wrote: > > > > 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 golang-nuts+unsubscr...@googlegroups.com. > > For more options, visit https://groups.google.com/d/optout. > -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.