我对XSD生成器有一个奇怪的行为,我真的无法解释。我得到了这样的XSD:
<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>
它源于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>
这只是XSD的一小部分,还有很多更复杂的类型。
因此,当我生成类似的类时,我会得到一个生成的类,它还有两个属性(除了我期望的5个属性):
public bool MinDuration_100msSpecified
和
public bool StageOnDemandSpecified
因此,"原始"属性"指定"被追加,类型现在是bool。有人能解释为什么会这样吗?
bool
属性意味着相关属性应该被序列化。
例如
如果将bool
MinDuration_100msSpecified
设置为false
,并将MinDuration_100ms
设置为300
,则在使用XmlSerializer
序列化对象时,不会序列化MinDuration_100ms
属性。
此功能可以将序列化的xml文件保存到最小。
设置minOccurs="1",其中元素是nillable的。例如:
<xs:element name="StageOnDemand" type="xs:boolean" nillable="true" minOccurs="1" />