开发者

Create an XSD example - Hours of Operation - One of Several Types

An example of some XML that could be sent:

<hours-of-operation>
        <monday hourType="custom">
            <open unit="AM">9:00</open> <!-- open/close or closed or 24hour -->
            <close unit="PM">5:00</close>
        </monday>
        <tuesday hourType="closed" />
        <wednesday hourType="24hour" />
        <thursday hourType="custom"&g开发者_JAVA百科t;
            <open unit="AM">9:00</open> <!-- open/close or closed or 24hour -->
            <close unit="PM">5:00</close>
        </thursday>
        <friday hourType="custom">
            <open unit="AM">9:00</open> <!-- open/close or closed or 24hour -->
            <close unit="PM">5:00</close>
        </friday>
        <saturday hourType="closed" />
        <sunday hourType="closed" />
    </hours-of-operation>

I want an XSD that defines the hours of operations element. If it makes things simpler, feel free to make the hourType an element as opposed to an attribute.

So basically, I need a day for each week, and it can EITHER have open and close hours, be closed, or be open 24 hours. Also, the requirements here are not lenient, I require all days of the week.

If it weren't clear, I don't want to know how you'd approach this problem in practice. I want XSD definitions for the XML that I posted, if you have a source that attempts to tackle this problem I want the specific XSD portion that applies exactly to this XML. I don't know much about XML schemas, and while I'm learning best I can quickly, the best thing I can get for this is the actual XSD code for this use case.


This would have been an acceptable answer, it doesn't validate that the time is time at all, it's just a string, but for the example posted would work.

<xs:element name="hours-of-operation">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="monday" type="day-hours"/>
                <xs:element name="tuesday" type="day-hours"/>
                <xs:element name="wednesday" type="day-hours"/>
                <xs:element name="thursday" type="day-hours"/>
                <xs:element name="friday" type="day-hours"/>
                <xs:element name="saturday" type="day-hours"/>
                <xs:element name="sunday" type="day-hours"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:complexType name="day-hours">
        <xs:choice>
            <xs:element name="twentyfourhours"/>
            <xs:element name="closed"/>
            <xs:element name="hours" type="hours"/>
        </xs:choice>
    </xs:complexType>
    <xs:complexType name="hours">
        <xs:sequence>
            <xs:element name="open" type="time"/>
            <xs:element name="close" type="time"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="time">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="unit" use="required" type="unit"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜