Re: [go-nuts] Regarding Invalid UTF-8 characters

2019-01-25 Thread Durga Someswararao G
Thanks.

On Fri, Jan 25, 2019 at 2:54 PM Wagner Riffel  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:
> CPUêÿ
> 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  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 := "CPUêÿ"
> >
> > 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()
> >
> > fmt.Println(out)
> >
> > fmt.Printf(out.Data,out.Mon)
> >
> > fmt.Println(err)
> >
> > //}
> >
> >
> >
> > }
> >
> >
> > but I am getting empty structure.
> >
> >
> > output:
> >
> > Hello World!
> >
> > &{CPUêÿ 0 -1}
> {CPUêÿ 0 -1}
> >
> > { }
> >
> > %!(EXTRA string=)
> >
> > --
> > 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.


Re: [go-nuts] Regarding Invalid UTF-8 characters

2019-01-25 Thread Wagner Riffel
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:
CPUêÿ
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  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 := "CPUêÿ"
>
> 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()
>
> fmt.Println(out)
>
> fmt.Printf(out.Data,out.Mon)
>
> fmt.Println(err)
>
> //}
>
>
>
> }
>
>
> but I am getting empty structure.
>
>
> output:
>
> Hello World!
>
> &{CPUêÿ 0 -1} 
> {CPUêÿ 0 -1}
>
> { }
>
> %!(EXTRA string=)
>
> --
> 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.


[go-nuts] Regarding Invalid UTF-8 characters

2019-01-25 Thread durgasomeswararao532
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 := "CPUêÿ"

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()

fmt.Println(out)

fmt.Printf(out.Data,out.Mon)

fmt.Println(err)

//}

 }


but I am getting empty structure.


output:

Hello World!

&{CPUêÿ 0 -1} 
{CPUêÿ 0 -1}

{ }

%!(EXTRA string=)

-- 
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.