I got a strange behaviour with the XSD generator I can’t really explain. I got an XSD like this:
<xs:complexType name="StageSequenceElement" mixed="false">
<xs:complexContent>
<xs:extension base="CoreObject">
<xs:sequence>
<xs:element name="Description" type="xs:string" minOccurs="0">
<xs:annotation>
<xs:documentation>Some Doc</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="StageRef" type="ObjectReference">
<xs:annotation>
<xs:documentation>...</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="MinDuration_100ms" type="xs:int" nillable="true" minOccurs="0">
<xs:annotation>
<xs:documentation>...</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="MaxDuration_100ms" type="xs:int" nillable="true">
<xs:annotation>
<xs:documentation>...</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="StageOnDemand" type="xs:boolean" nillable="true" minOccurs="0">
<xs:annotation>
<xs:documentation>...</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
it is derived from CoreObject:
<xs:complexType name="CoreObject">
<xs:sequence>
<xs:element name="No" type="xs:int">
<xs:annotation>
<xs:documentation>...</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
This is just a small part of the XSD, there are a lot more complex types.
So when I generate the classes similar to this, I get a generated class which has two more properties (in addition to the 5 which I would expect):
public bool MinDuration_100msSpecified
and
public bool StageOnDemandSpecified
So to the “original” property “Specified” was appended and the type is now bool.
Can anyone explain why this is so?
the
boolattribute means the related attribute should be serialized.e.g.
If the
boolMinDuration_100msSpecifiedis set tofalse, and you set theMinDuration_100msto be300, when you useXmlSerializerto serialize the object, theMinDuration_100msattribute won’t be serialized.This feature can save the serialized xml file to be minimal.