Golang encoding/xml.MarshalerAttr type example
package encoding/xml
MarshalerAttr is the interface implemented by objects that can marshal themselves into valid XML attributes.
MarshalXMLAttr returns an XML attribute with the encoded value of the receiver. Using name as the attribute name is not required, but doing so will enable Unmarshal to match the attribute to the correct struct field. If MarshalXMLAttr returns the zero attribute Attr{}, no attribute will be generated in the output. MarshalXMLAttr is used only for struct fields with the "attr" option in the field tag.
Golang encoding/xml.MarshalerAttr type usage example
...
if fv.CanInterface() && fv.Type().Implements(marshalerAttrType) {
attr, err := fv.Interface().(MarshalerAttr).MarshalXMLAttr(name) // <-- here
if err != nil {
return err
}
if attr.Name.Local != "" {
start.Attr = append(start.Attr, attr)
}
continue
}
...
Reference :
Advertisement
Something interesting
Tutorials
+7.8k Golang : Getting Echo framework StartAutoTLS to work
+10.9k Golang : Sieve of Eratosthenes algorithm
+5.4k Unix/Linux/MacOSx : How to remove an environment variable ?
+17.7k Golang : Read data from config file and assign to variables
+62.7k Golang : Convert HTTP Response body to string
+7.3k Golang : Fixing Gorilla mux http.FileServer() 404 problem
+14.6k Golang : GUI with Qt and OpenCV to capture image from camera
+15.2k Golang : How to add color to string?
+7.1k Restart Apache or Nginx web server without password prompt
+15k Golang : How do I get the local IP (non-loopback) address ?
+22.1k Golang : Join arrays or slices example
+16.3k Golang : Find out mime type from bytes in buffer