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
+19.9k Golang : How to get time from unix nano example
+13.1k Golang : Handle or parse date string with Z suffix(RFC3339) example
+12.3k Golang : Validate email address
+10k CodeIgniter : Load different view for mobile devices
+7.5k Golang : Handling Yes No Quit query input
+41.4k Golang : Convert string to array/slice
+8.2k Golang : Reverse text lines or flip line order example
+23.9k Golang : Fix type interface{} has no field or no methods and type assertions example
+7.9k Golang : Grayscale Image
+10.5k Swift : Convert (cast) String to Integer
+18.7k Unmarshal/Load CSV record into struct in Go
+12.5k Golang : "https://" not allowed in import path