Solved

XSD how to specify null in enum

Posted on 2010-08-31
6
2,140 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
DevOps Toolchain Recommendations

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

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 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

13 Experts available now in Live!

Get 1:1 Help Now