nicholsf
asked on
XSD how to specify null in enum
For XSD definition, how can null be included as enum for a field defined as string?
Is this correct: <xs:enumeration value="null"/>
<xs:element name="status_color" nillable="true">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="G"/>
<xs:enumeration value="R"/>
<xs:enumeration value="Y"/>
<xs:enumeration value="null"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
I'm using xsd.exe /xsd2code.exe and it turns the code into this: @null
[System.CodeDom.Compiler.G eneratedCo deAttribut e("Xsd2Cod e", "3.3.0.31927")]
[System.SerializableAttrib ute()]
[System.Xml.Serialization. XmlTypeAtt ribute(Ano nymousType =true, Namespace="http://pmve.web.boeing.com/action_item_dtl_in")]
public enum status_color {
G,
R,
Y,
@null,
}
Is this correct: <xs:enumeration value="null"/>
<xs:element name="status_color" nillable="true">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="G"/>
<xs:enumeration value="R"/>
<xs:enumeration value="Y"/>
<xs:enumeration value="null"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
I'm using xsd.exe /xsd2code.exe and it turns the code into this: @null
[System.CodeDom.Compiler.G
[System.SerializableAttrib
[System.Xml.Serialization.
public enum status_color {
G,
R,
Y,
@null,
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
What about xsd and is this valid for defining null:
<xs:enumeration value="null"/>
I think it is but I'm not a 100%
Note: I realize that nillable="true" for the element will work. but if you want a list of valid enum values.
<xs:enumeration value="null"/>
I think it is but I'm not a 100%
Note: I realize that nillable="true" for the element will work. but if you want a list of valid enum values.
I don't have access to my copy of XMLSpy ATM; the best I can offer right now would be to try empty string for nil:
<xs:enumeration value=""/>
It seems to me, however, that having a value of nil defeats the purpose of having an enumeration. An enumeration is a way of saying: "This item MUST be one of these values." A value of nil seems counter-intuitive to me.
ASKER
Many thanks for providing the info on the @ in C#.
That was helpful..increased my knowledge of C#.
That was helpful..increased my knowledge of C#.
E.g.
@int
@struct
@class