Firstly, you can name the struct fields whatever you like, except it needs to start with a capital letter. It doesn't have to match the XML element name at all.
Secondly, what you're looking at here is an XML namespace declaration.
The special attribute
and makes the local namespace prefix "edmx" available to this element and its children.
The namespace prefix is arbitrary and can be chosen by whoever generates the XML document. The following XML is equivalent and needs to be parsed identically:
You *could* pick up the xmlns attribute explicitly if you want, by matching the pseudo-namespace "xmlns" (see
here):
type Metadata struct {
Version string `xml:"Version,attr"`
Namespace string `xml:"xmlns edmx,attr"`
}
However, normally you don't want to do this, because whoever generates the XML is completely free to use whatever namespace prefix they like, e.g. "womble" instead of "edmx" as shown above.
What you should do instead is to get encoding/xml to match the actual namespace. Here is an example: