i'm learning to create XML in Go. Here's my code:
type Request struct {
XMLName xml.Name `xml:"request"`
Action string `xml:"action,attr"`
...
Point []point `xml:"point,omitempty"`
}
type point struct {
geo string `xml:"point"`
radius int `xml:"radius,attr"`
}
func main() {
v := &Request{Action: "get-objects"}
v.Point = append(v.Point, point{geo: "55.703038, 37.554457", radius: 10})
output, err := xml.MarshalIndent(v, " ", " ")
if err != nil {
fmt.Println("error: %v\n", err)
}
os.Stdout.Write([]byte(xml.Header))
os.Stdout.Write(output)
}
I expect the output to be like:
<?xml version="1.0" encoding="UTF-8"?>
<request action="get-objects">
<point radius=10>55.703038, 37.554457</point>
</request>
But what I'm getting is:
<?xml version="1.0" encoding="UTF-8"?>
<request action="get-objects">
<point></point>
</request>
What am I missing or doing wrong? Because the "name,attr" thing works perfect for everything else (for example, for the "request" field, as you can see). Thanks.