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
+17.1k Golang : XML to JSON example
+8k Golang : Sort words with first uppercase letter
+7.3k Golang : Of hash table and hash map
+19.4k Golang : Fix cannot download, $GOPATH not set error
+11.6k Golang : Fuzzy string search or approximate string matching example
+15.2k Golang : Get HTTP protocol version example
+7.3k Golang : How to convert strange string to JSON with json.MarshalIndent
+5.1k Linux : How to set root password in Linux Mint
+4.7k Unix/Linux : How to pipe/save output of a command to file?
+20.2k Golang : Determine if directory is empty with os.File.Readdir() function
+16.4k Golang : Send email and SMTP configuration example
+15.6k Golang : rune literal not terminated error