Otherwise the above results in generating (xml annotations removed for brevity):
type Leaf struct {}
type Composite struct {
Leaf Leaf
Delegate Composite
}
The above cannot compile. Composite struct contains itself which would result in infinite expansion of the struct.
Instead, when introducing a pointer of a nillable element:
type Leaf struct {}
type Composite struct {
Leaf *Leaf
Delegate *Composite
}
The above compiles.
The example using pointers also matches Go pattern of using nil to explicitly mark absence where only some of many values are expected (semantics of xs:choice).
Use pointer type for nillable elements as described in xsd.Element.Nillable.
This allows in defining a recursive complexType, like so:
Otherwise the above results in generating (xml annotations removed for brevity):
The above cannot compile. Composite struct contains itself which would result in infinite expansion of the struct.
Instead, when introducing a pointer of a nillable element:
The above compiles.
The example using pointers also matches Go pattern of using nil to explicitly mark absence where only some of many values are expected (semantics of
xs:choice
).