Xsd2Code omits certain fields
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:att开发者_JS百科ribute 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?
I'd say it is by design. A restriction can't add NEW attributes or elements or anything to the base type.
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.
精彩评论