473,400 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

Flags style enum?

Is there a way to represent a [Flags] style enum in XML Schema? Say I have
a flags enum like so:

[Flags]
public enum dayOfWeek {
Mon,
Tue,
Wed,
All = Mon | Tue | Wed;
}

I'd like to have my XML be able to use an element attribute like so:

<SomeElement dayOfWeek="Mon|Wed" />

Is this possible with xsd:enumeration? If not, I can fall back to making
this attribute type xsd:string it's just that I don't get the benefits of
schema validation on the values anymore. Or can I? Is there a way to hook
schema validation for a particular attribute value?

--
Keith
Nov 12 '05 #1
4 6722
Keith Hill wrote:
Is there a way to represent a [Flags] style enum in XML Schema? Say I have
a flags enum like so:

[Flags]
public enum dayOfWeek {
Mon,
Tue,
Wed,
All = Mon | Tue | Wed;
}

I'd like to have my XML be able to use an element attribute like so:

<SomeElement dayOfWeek="Mon|Wed" />


Is it important to have | as separator? List values in XSD are separated
by space. Here is an example:

<xs:simpleType name="dayOfWeekType">
<xs:restriction base="xs:string">
<xs:enumeration value="Mon"/>
<xs:enumeration value="Wed"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="SomeElement">
<xs:complexType>
<xs:attribute name="dayOfWeek" use="required">
<xs:simpleType>
<xs:list itemType="dayOfWeekType"/>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>

Then you can list enumerated values:

<SomeElement dayOfWeek="Mon Wed"/>

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2
Keith Hill wrote:
Is there a way to represent a [Flags] style enum in XML Schema? Say I have
a flags enum like so:

[Flags]
public enum dayOfWeek {
Mon,
Tue,
Wed,
All = Mon | Tue | Wed;
}

I'd like to have my XML be able to use an element attribute like so:

<SomeElement dayOfWeek="Mon|Wed" />


Is it important to have | as separator? List values in XSD are separated
by space. Here is an example:

<xs:simpleType name="dayOfWeekType">
<xs:restriction base="xs:string">
<xs:enumeration value="Mon"/>
<xs:enumeration value="Wed"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="SomeElement">
<xs:complexType>
<xs:attribute name="dayOfWeek" use="required">
<xs:simpleType>
<xs:list itemType="dayOfWeekType"/>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>

Then you can list enumerated values:

<SomeElement dayOfWeek="Mon Wed"/>

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #3
"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:es**************@TK2MSFTNGP12.phx.gbl...
Is it important to have | as separator? List values in XSD are separated
by space. Here is an example:


Nope. I can live with a space. Thanks!

--
Keith
Nov 12 '05 #4
"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:es**************@TK2MSFTNGP12.phx.gbl...
Is it important to have | as separator? List values in XSD are separated
by space. Here is an example:


Nope. I can live with a space. Thanks!

--
Keith
Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Keith Hill | last post by:
Is there a way to represent a style enum in XML Schema? Say I have a flags enum like so: public enum dayOfWeek { Mon, Tue, Wed, All = Mon | Tue | Wed; }
1
by: | last post by:
Would be nice to specify an incremenet or decremenet as an attribute in an enum so I can for example have the following... enum SomeEnum { A = 0, B, // 2 C, // 4 D /6
3
by: Ignacio X. Domínguez | last post by:
Hi. I'm using the | operator to use multiple flags in a variable. For example: const int flag1 = 0x00000001; const int flag2 = 0x00000002; const int flag3 = 0x00000004; int Flags = flag2 |...
1
by: Dwight.Dexter | last post by:
I have an enum variable. Is there some way to cast an int or BitArray and get my enum value? I have to communicate with an old C-style sever so I get an array of bits("0","1"). But I'm using an...
4
by: Paul E Collins | last post by:
The help file says that "bit fields can be combined using a bitwise OR operation, whereas enumerated constants cannot", and yet this code works: enum Blah { a, b, c }; // without .... Blah x...
6
by: Charles Law | last post by:
I have the following structure (for example) that I wish to convert for use in VB.NET. What would be the best way to do it? Ideally, it would convert directly to allow access to the bit fields in...
2
by: Chad | last post by:
I've used bitwise enums before (powers of 2) and have used AND and OR operator to determine which individual flags have been set, but I have never used the <Flags()> _ attribute What advantage...
2
by: Jigar.Patel | last post by:
Hi, I have following enum definition. public enum OperationTypes { All = 1, New = 2, View = 4,
2
by: JB | last post by:
Hi All, I'm pulling my hair over this and could really do with a bit of help. I'm using various different enums as bit fields and I'd like to create a set of generic Functions or Subs to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.