开发者

Day of week XSD enum

I'm trying to represent a class that, amongst other things, has a set of days of the week - for example, it could be empty, it could be Monday, Wednesday, and Thursday, or could be all seve开发者_如何学Cn days. Obviously it shouldn't allow the same day more than once. I'm also trying to generate the classes from an XSD using xsd.exe or another tool.

I'm not asking which method is best, but for answers on how to accomplish this in any sensible way. For example, I don't mind whether the class has a Boolean for each day of the week, or a hash set limited to the values in an enum. The target language is C#/.NET3.5.

Trouble is, I've got a mind blank on how to represent this in XSD format! Here's what I've got so far:

<xs:simpleType name="daysOfWeek">
    <xs:restriction base="xs:string">
        <xs:enumeration value="Monday"/>
        <xs:enumeration value="Tuesday"/>
        <xs:enumeration value="Wednesday"/>
        <xs:enumeration value="Thursday"/>
        <xs:enumeration value="Friday"/>
        <xs:enumeration value="Saturday"/>
        <xs:enumeration value="Sunday"/>
    </xs:restriction>
</xs:simpleType>

<xs:complexType name="runDays">
    <!-- Set of days of the week goes here -->
</xs:complexType>


You could define a node that has a specific list of child nodes where every node can only occure once but can be ommitted.

<xs:complexType>
    <xs:sequence>
        <xs:element name="Monday"
                    minOccurs="0"
                    maxOccurs="1">
          <xs:complexType>
          </xs:complexType>
        </xs:element>
        <xs:element name="Tuesday"
                    minOccurs="0"
                    maxOccurs="1">
          <xs:complexType>
          </xs:complexType>
        </xs:element>

<!-- etc. ... -->

    </xs:sequence>
</xs:complexType>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜