1...">

XSD: minInclusive and attribute together

It seems I cannot easily have an XSD declaration for this simple XML

<root>
    <weekday name="Sunday">1</weekday>
</root>

where weekday is a restricted int from 1 to 7 and has a string type name attribute

Any tips?

Thanks for your support!

+5
source share
1 answer

Of course. You need a complex type (which adds the name attribute) derived from a simple type (which limits an integer from one to 7):

<xs:simpleType name="NumericWeekday">
    <xs:restriction base="xs:int">
        <xs:minInclusive value="1"/>
        <xs:maxInclusive value="7"/>
    </xs:restriction>
</xs:simpleType>
<xs:complexType name="Weekday">
    <xs:simpleContent>
        <xs:extension base="NumericWeekday">
            <xs:attribute name="name" type="xs:string"/>
        </xs:extension>
    </xs:simpleContent>
</xs:complexType>

I will leave it to you to include the name attribute in the enumeration.

+6
source

All Articles