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
+10k Golang : Convert octal value to string to deal with leading zero problem
+40.1k Golang : UDP client server read write example
+17.1k Golang : XML to JSON example
+24.1k Golang : Upload to S3 with official aws-sdk-go package
+13.1k Golang : Convert(cast) uintptr to string example
+16.4k Golang : Send email and SMTP configuration example
+5.2k Python : Create Whois client or function example
+25.7k Golang : How to write CSV data to file
+28.5k Golang : Change a file last modified date and time
+9.9k Golang : Translate language with language package example
+22.2k Golang : Print leading(padding) zero or spaces in fmt.Printf?
+6.3k WARNING: UNPROTECTED PRIVATE KEY FILE! error message