Solved

XSD how to specify null in enum

Posted on 2010-08-31
6
2,184 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 75

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 75

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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 
LVL 75

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 75

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What Does This C# Code Block Do? 5 58
VB.Net. Reading xml value 6 30
How to implement an additional command 16 40
parsing xml using powershell 6 20
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

820 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