Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSD: minInclusive and attribute together

Tags:

xml

xsd

It seems I can't 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 name attribute of type string

Any advice?

Thanks for your support!

like image 412
neurino Avatar asked Apr 06 '10 10:04

neurino


1 Answers

Sure you can. You need a complex type (that adds the name attribute) derived from a simple type (that constrains the 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 turn the name attribute into an enumeration.

like image 103
xcut Avatar answered Sep 23 '22 22:09

xcut