Xsd2Code omits certain fields

1.6k views Asked by At

I'm using Xsd2Code to generate classes from an XML schema. It works for some complex types like the following:

<xs:complexType name="AsiguratB1Type">
        <xs:sequence>
            <xs:element name="asiguratB11" type="AsiguratB11Type" minOccurs="0" maxOccurs="10"/>
        </xs:sequence>
        <xs:attribute name="B1_1" type="typ:TipAsiguratSType" use="required"/>
        <xs:attribute name="B1_2" type="typ:FlagSType" use="required"/>
        <xs:attribute name="B1_3" type="typ:TipContractSType" use="required"/>
        <xs:attribute name="B1_4" type="typ:OreNormaZiSType" use="required"/>
        <xs:attribute name="B1_5" type="typ:Pozitiv15SType"/>
        <xs:attribute name="B1_6" type="typ:Pozitiv3SType"/>
        <xs:attribute name="B1_7" type="typ:Pozitiv3SType"/>
        <xs:attribute name="B1_8" type="typ:Pozitiv3SType"/>
        <xs:attribute name="B1_9" type="typ:Pozitiv2SType"/>
        <xs:attribute name="B1_10" type="typ:Pozitiv15SType"/>
        <xs:attribute name="B1_15" type="typ:Pozitiv2SType"/>
    </xs:complexType>

... while for others (example below) it just generates blank classes (only serialization routines, no fields).

<xs:complexType name="AngajatorAType">
        <xs:complexContent>
            <xs:restriction base="xs:anyType">
                <xs:attribute name="A_codOblig" type="typ:CodObligSType" use="required"/>
                <xs:attribute name="A_codBugetar" type="typ:CodBugetarSType" use="required"/>
                <xs:attribute name="A_datorat" type="typ:Pozitiv15SType" use="required"/>
                <xs:attribute name="A_deductibil" type="typ:Pozitiv15SType"/>
                <xs:attribute name="A_plata" type="typ:Pozitiv15SType" use="required"/>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>

The same thing happens with xsd.exe from the VS2010 toolset. What do you think could be the problem?

2

There are 2 answers

1
fejesjoco On

I'd say it is by design. A restriction can't add NEW attributes or elements or anything to the base type.

0
Sentient On

I think there might be an issue how xsd2code is handling the minOccus=0 when you target 4.0 framework. Would you be able to temporarily remove that and see what is serialized?

What also seems to work is to target the 3.5 framework and include the xml attributes.