Recently I starting using Go. I am facing one problem while parsing XML.
Here is the issue:
I am successfully able to parse the following XML:
<Root>
<cookie name="e1">hsdhsdhs</cookie>
<cookie name="e2">sssss</cookie>
<cookie name="e3">null</cookie>
<info>
<name>sam</name>
</info>
</Root>
Here are the structs:
type Profile struct {
RootElement xml.Name `xml:"Root"`
CookieList []Cookie `xml:"cookie"`
Info Information `xml:"info"`
}
type Cookie struct {
Name string `xml:"name,attr"`
Value string `xml:",chardata"`
}
type Information struct {
Name string `xml:"name"`
}
And the above struct is working fine.
profile := Profile{}
xml.Unmarshal([]byte(xmlString), &profile)
jsonData, _ := json.Marshal(profile)
fmt.Println(string(jsonData))
But as I keep prolog in XML:
<?xml version="1.0" encoding="EUC-JP"?>
<Root>
<cookie name="e1">hsdhsdhs</cookie>
<cookie name="e2">sssss</cookie>
<cookie name="e3">null</cookie>
<info>
<name>sam</name>
</info>
</Root>
then while printing, no data is displaying inside the JSON.
Not sure what is the issue here with Prolog.