go-xml
go-xml copied to clipboard
add XMLName field to generated structs
Without this PR, marshalling a struct generated by xsdgen will not set it's name and namespace correctly. As fas as I can tell the standard practice in go is to add the field XMLName of type xml.Name to structs you want to marshal to XML. That fiel's tag will then be used for setting the elements name and namespace.
see https://pkg.go.dev/encoding/xml#Marshal
I just realized, that this should only be done for top level elements. I'll need to figure out how to determine that at the code generation stage.
I think you need to manually create a top level struct with the XMLName xml.Name field and embed the top level structure you want to unmarshall using that