Problem during XML Deserialize to object

Aug 1, 2012 at 9:49 AM

I have generated the class from XSD by Xsd2Code.

The XSD file like the following:

      <xs:element name="Specification" minOccurs="0" maxOccurs="unbounded">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="Title" type="xs:string"></xs:element>
            <xs:element name="Options" minOccurs="0">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="Value" maxOccurs="unbounded">
                    <xs:complexType>
                      <xs:simpleContent>
                        <xs:extension base="xs:string">
                          <xs:attribute name="Checked" type="xs:boolean" default="false"/>
                        </xs:extension>
                      </xs:simpleContent>
                    </xs:complexType>
                  </xs:element>
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>

My code of Deserialize is:

XMLClass obj = XMLClass.Deserialize(strXML);

The value of strXML like the following:

    <Specification>
      <Title>Color</Title>
      <Options>
        <Value>Red</Value>
        <Value>Green</Value>
      </Options>
    </Specification>
    <Specification>
      <Title>Thickness</Title>
    </Specification>

When I debug the program, I found the value of obj is not what I want:

The 1st Specification has TAG Options, it is correct which what I want. But the 2nd Specification also has TAG Options(though the count of Options' children element is 0), it is not what I want. In my mind, I think the 2nd should has no TAG of Options, because in the definition of XSD, the minOccurs of Options was set 0.

Had I make a wrong configuration of Xsd2Code generation?

Thanks for your help!