XSD Tool Adds Specified To Specific Properties / Fields When Generating C # Code

I have strange behavior with an XSD generator that I cannot explain. I got the XSD as follows:

<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 only a small part of the XSD, a much more complex type exists.

Therefore, when I generate classes similar to this , I get a generated class that has two more properties (in addition to 5, which I would expect):

 public bool MinDuration_100msSpecified 

and

 public bool StageOnDemandSpecified 

So, the property "Specified" was added to the "original" property, and now the type is bool. Can anyone explain why this is so?

+8
c # code-generation
source share
2 answers

The bool attribute means that the associated attribute must be serialized.

eg.

If bool MinDuration_100msSpecified set to false and you set MinDuration_100ms to 300 when you use the XmlSerializer to serialize the object, the MinDuration_100ms attribute MinDuration_100ms not be serialized.

This function can save a minimal serialized xml file size.

+9
source share

Set minOccurs = "1" where the item is nillable. For example:

 <xs:element name="StageOnDemand" type="xs:boolean" nillable="true" minOccurs="1" /> 
+2
source share

All Articles