I’ve generated structure in Go language from XSD using xsdgen tool. For example,
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" ...>
...
<xs:complexType name="BaseRequest">
<xs:sequence>
<xs:element name="element1" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="GenericObject" abstract="true">
<xs:sequence>
<xs:element name="id" type="string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="CreateObjectRequest">
<xs:complexContent>
<xs:extension base="BaseRequest">
<xs:sequence>
<xs:element name="createObject" type="GenericObject"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
...
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:x1="http://example.com" >
<xs:import namespace="http://example.com" schemaLocation=<location of xsd-1/>
<xs:complexType name="ABC">
<xs:complexContent>
<xs:extension base="x1:GenericObject">
<xs:sequence>
<xs:element name="data" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:schema>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:x1="http://example.com" >
<xs:import namespace="http://example.com" schemaLocation=<location of xsd-1/>
<xs:complexType name="FOO">
<xs:complexContent>
<xs:extension base="x1:GenericObject">
<xs:sequence>
<xs:element name="value" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:schema>
From above XSDs, these Go structures are generated.
type CreateObjectRequest struct {
element1 string `xml:"element1"`
CreateObject GenericObject `xml:"createObject"`
}
type GenericObject struct {
id string `xml:"id"`
}
type ABC struct {
id string `xml:"id"`
data string `xml:"data,omitempty"`
}
type FOO struct {
id string `xml:"id"`
value string `xml:"value,omitempty"`
}
Here type of “CreateObject” in “CreateObjectRequest” structure is “GenericObject”. But I want to generate “CreateObjectRequest” structure for derived class ABC and FOO. How can I do so? Is xsdgen support hierarchical inheritance?
New contributor
Memo Karpa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.