Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xs:choice duplicated element #378

Open
kubajt opened this issue May 5, 2023 · 3 comments
Open

xs:choice duplicated element #378

kubajt opened this issue May 5, 2023 · 3 comments

Comments

@kubajt
Copy link

kubajt commented May 5, 2023

"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.

@mganss
Copy link
Owner

mganss commented May 5, 2023

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>

@michaelplavnik
Copy link

michaelplavnik commented Dec 22, 2023

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>

@mganss
Copy link
Owner

mganss commented Jan 12, 2024

@michaelplavnik Could this be a duplicate of #475?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants