Groups | Blog | Home
all groups > dotnet xml > june 2004 >

dotnet xml : Flags style enum?



Keith Hill
6/21/2004 3:44:24 PM
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

Keith Hill
6/22/2004 10:53:14 AM
[quoted text, click to view]

Nope. I can live with a space. Thanks!

--
Keith

Oleg Tkachenko [MVP]
6/22/2004 1:43:15 PM
[quoted text, click to view]

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]
AddThis Social Bookmark Button