Reputation: 3113
I have this XML reader struct:
type Recurlyservers struct {
XMLName xml.Name `xml:"servers"`
Version string `xml: "version,attr"`
Svs []server `xml: "server"`
Description string `xml:",innerxml"`
}
What is the meaning of this xml:"servers"
or xml: "version,attr"
? I don't know what this `` is. I would like to search in Google but I don't know it's name. What is it? and can I use the standard struct without this? Because the XML reading is not working without this.
Upvotes: 0
Views: 367
Reputation: 48114
Those are called field tags. They're used by the xml encoder/decoder to map the property names to the values in the actual data. In your example they're completely necessary because the fields in XML are lower cased, in Go to have fields on a struct exported they have to be upper cased. Since the xml names diverge from the field names on your type, you have to specify what goes where for the encoding package.
This same convention is used from almost all data transformation/encoding/storage libraries.
Upvotes: 5