开发者

Day of week XSD enum

开发者 https://www.devze.com 2023-03-28 21:36 出处:网络
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开发者_如何

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

精彩评论

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