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
+18.5k Golang : Write file with io.WriteString
+10.3k Golang : Convert file content to Hex
+8.1k Golang : Variadic function arguments sanity check example
+13.4k Golang : Verify token from Google Authenticator App
+5.5k Golang : Display advertisement images or strings on random order
+7.9k Golang : Grayscale Image
+10.5k RPM : error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
+8.8k Golang : Heap sort example
+7.2k Golang : Null and nil value
+17.8k Golang : Iterate linked list example
+19.6k Golang : Get current URL example
+6.3k Javascript : Generate random key with specific length