[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2434
  • Last Modified:

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.GeneratedCodeAttribute("Xsd2Code", "3.3.0.31927")]
    [System.SerializableAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://pmve.web.boeing.com/action_item_dtl_in")]
    public enum status_color {
        G,
        R,
        Y,
        @null,
    }
   
0
nicholsf
Asked:
nicholsf
  • 4
  • 2
1 Solution
 
käµfm³d 👽Commented:
Enums in C# are value types--hence they cannot take a value of null. As far as the "@null", "null" is a reserved word in C#. Because of this, the "@" was pre-pended to it. You can use any reserved word as an identifier in C# if you preface it with an "at" symbol.

E.g.

   @int
   @struct
   @class
0
 
käµfm³d 👽Commented:
I should have made the examples a bit clearer:

    char @int = 'a';
    string @struct = "hello";
    Point @class = new Point(1, 3);
0
 
nicholsfAuthor Commented:
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.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
käµfm³d 👽Commented:
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=""/>

Open in new window

0
 
käµfm³d 👽Commented:
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.
0
 
nicholsfAuthor Commented:
Many thanks for providing the info on the @ in C#.
That was helpful..increased my knowledge of C#.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now