1

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?

  • Could you make a test case? I mean, a simple XML Schema where the behaviour is reproducible? – Sergey Shandar Feb 19 '11 at 12:54
  • It seems that attributes placed between tags are not generated in the class. I'm looking into the problem ATM. –  Feb 19 '11 at 13:09
  • From W3Schools: "The complexContent element defines extensions or restrictions on a complex type that contains mixed content or elements only". Since the base type in my case is "anyType", which has no restrictions and corresponds to "object" in C#, I wonder if the complexContent tag is redundant. –  Feb 19 '11 at 13:27

2 Answers2

0

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

fejesjoco
  • 11,763
  • 3
  • 35
  • 65
  • I'm going to remove the unnecessary tags and get back with the results. I just hope the XML will be parsed correctly by the 3rd party software. –  Feb 20 '11 at 14:31
0

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.

Sentient
  • 2,185
  • 2
  • 19
  • 20