go-xml
go-xml copied to clipboard
arrays of non-trivial builtins
Consider the element declaration below (note the "maxOccurs" attribute)
<element name="timestamps" type="xsd:dateTime" minOccurs="0" maxOccurs="unbounded">
In Go, the ideal declaration for this type would be []time.Time. For scalar types, we can get away with converting a *time.Time to an *xsdDateTime, a private type that we can attach MarshalXML/UnmarshalXML methods to. This doesn't work with slice types: https://play.golang.org/p/ZAOS7gzcUk .
Currently, xsdgen doesn't work at all for this scenario; it will generate code that tries to convert a *[]time.Time to an *xsdDateTime, which fails to compile.
I really like the fact that generated code uses basic types like time.Time and []byte (for base64Binary) rather than exporting custom types, and would like to keep that property, if feasible. The most obvious way forward, then, is to add plural versions of all the "helper types":
type xsdDateTimeSlice []time.Time
type xsdBase64BinarySlice [][]byte
The accompanying methods would then look very similar to their scalar versions (see the principle here: https://play.golang.org/p/f715VAnArD)