cornelius/kode

[kxml_compiler]Add support for choice

Opened this issue · 1 comments

I have an XSD with the following element:

	<xs:element name="Invoice">
		<xs:annotation>
			<xs:documentation xml:lang="hu">XML root element, számla vagy módosítás adatait leíró típus, amelyet BASE64 kódoltan tartalmaz az invoiceApi sémaleíró invoice elementje</xs:documentation>
			<xs:documentation xml:lang="en">XML root element, invoice or modification data type in BASE64 encoding, equivalent with the invoiceApi schema definition's invoice element</xs:documentation>
		</xs:annotation>
		<xs:complexType>
			<xs:complexContent>
				<xs:extension base="InvoiceType"/>
			</xs:complexContent>
		</xs:complexType>
	</xs:element>

Where the InvoiceType is defined as the following:

<xs:complexType name="InvoiceType">
		<xs:annotation>
			<xs:documentation xml:lang="hu">Az adatszolgáltatás fő típusa</xs:documentation>
			<xs:documentation xml:lang="en">Main type of the data exchange</xs:documentation>
		</xs:annotation>
		<xs:choice>
			<xs:element name="invoiceExchange" type="InvoiceExchangeType">
				<xs:annotation>
					<xs:documentation xml:lang="hu">A számla adatszolgáltatás adatai</xs:documentation>
					<xs:documentation xml:lang="en">Invoice exchange data</xs:documentation>
				</xs:annotation>
			</xs:element>
			<xs:element name="invoiceAnnulment" type="InvoiceAnnulmentType">
				<xs:annotation>
					<xs:documentation xml:lang="hu">Korábbi adatszolgáltatás technikai érvénytelenítésének adatai</xs:documentation>
					<xs:documentation xml:lang="en">Data of technical annulment concerning previous data exchange</xs:documentation>
				</xs:annotation>
			</xs:element>
		</xs:choice>
	</xs:complexType>

What would be the best generated code for this?

Have two properties (invoiceExchange and invoiceAnnulment) in the InvoiceType class, and create some logic to see which have been set and initialized first?

Yes, this is a case which is not easy to reflect well in a static class hierarchy. So having two fields in the class and have explicit logic and functions to tell which one is set might be the best solution.