XmlSchemaClassGenerator
XmlSchemaClassGenerator copied to clipboard
xs:choice duplicated element
"xs:choice" with same names in branches causes error "The XML element '...' from namespace '...' is already present in the current scope."
For example:
<xs:choice minOccurs="0">
<xs:sequence>
<xs:element name="MinAge" type="PersonAgeType" minOccurs="1"></xs:element>
<xs:element name="MaxAge" type="PersonAgeType" minOccurs="0"></xs:element>
</xs:sequence>
<xs:sequence>
<xs:element name="MaxAge" type="PersonAgeType" minOccurs="1"></xs:element>
</xs:sequence>
</xs:choice>
gives
[System.Xml.Serialization.XmlElementAttribute("MaxAge")]
public uint MaxAgeValue { get; set; }
...
[System.Xml.Serialization.XmlElementAttribute("MaxAge")]
public uint MaxAge1Value { get; set; }
"MaxAge" is duplicated.
Support for choices is incomplete, see https://github.com/mganss/XmlSchemaClassGenerator#choice-elements I'd recommend changing the input schema to something like this (just for the purpose of generating classes):
<xs:complexType>
<xs:sequence>
<xs:element name="MinAge" type="PersonAgeType" minOccurs="0">
</xs:element>
<xs:element name="MaxAge" type="PersonAgeType" minOccurs="0">
</xs:element>
</xs:sequence>
</xs:complexType>
Another example from the standard schema fpml-valuation-4.6.xsd (e.g. one cannot change it). It generates collection property
List<DateTime> AdjustedData instead of optional value. Interesting enough, this happens when generating interface for the group. Class that implements this interface actually generates a scalar property.
<xsd:group name="AdjustedAndOrUnadjustedDate.model">
<xsd:annotation>
<xsd:documentation xml:lang="en">Contains at least one of an adjusted date and and unadjusted date, using the usual meanings of those terms.</xsd:documentation>
</xsd:annotation>
<xsd:choice>
<xsd:sequence>
<xsd:element name="unadjustedDate" type="xsd:date" />
<xsd:element name="adjustedDate" type="xsd:date" minOccurs="0" />
</xsd:sequence>
<xsd:element name="adjustedDate" type="xsd:date" />
</xsd:choice>
</xsd:group>
@michaelplavnik Could this be a duplicate of #475?