Question

I have been provided an XSD file that I have generated code from using XSD.exe but it is not functioning in the way that I'm expecting.

    <xsd:element name="Claims">
      <xsd:complexType>
        <xsd:sequence>
          <xsd:element maxOccurs="unbounded" name="Claim" minOccurs="0">
            <xsd:complexType>
              <xsd:sequence>
                <xsd:element name="ClaimDate" type="xsd:dateTime" />
                <xsd:element name="ClaimDesc" type="xsd:string" />
                ....
              </xsd:sequence>
            </xsd:complexType>
          </xsd:element>
        </xsd:sequence>
      </xsd:complexType>
    </xsd:element>

The expectation is that if there are no claims, then an empty node is sent through but the generated code comes out as

[System.Xml.Serialization.XmlArrayItemAttribute("Claim", IsNullable=false)]
public QuoteRequestClaim[] Claims {
    get {
        return this.claimsField;
    }
    set {
        this.claimsField = value;
    }
}

meaning that I cannot pass this empty node through. Is this a quirk in XSD.exe or does the XSD need to be modified to make this work?

Was it helpful?

Solution

I have solved this myself. The XSD that I had been provided with needed changing to

<xsd:sequence maxOccurs="unbounded" minOccurs="0">
      <xsd:element name="Claim">
      </xsd:element>
</xsd:sequence>

The minOccurs and the maxOccurs were in the wrong place.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top