Solved

XSD how to specify null in enum

Posted on 2010-08-31
6
2,115 Views
Last Modified: 2012-05-10
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
Comment
Question by:nicholsf
  • 4
  • 2
6 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 33571837
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
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 350 total points
ID: 33571845
I should have made the examples a bit clearer:

    char @int = 'a';
    string @struct = "hello";
    Point @class = new Point(1, 3);
0
 

Author Comment

by:nicholsf
ID: 33571949
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 33572033
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
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 33572044
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
 

Author Closing Comment

by:nicholsf
ID: 33685075
Many thanks for providing the info on the @ in C#.
That was helpful..increased my knowledge of C#.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now